{"id":68,"date":"2023-02-08T12:51:24","date_gmt":"2023-02-08T04:51:24","guid":{"rendered":"http:\/\/zkxx.xyz\/?p=68"},"modified":"2023-02-17T15:24:43","modified_gmt":"2023-02-17T07:24:43","slug":"win32%e5%92%8cvc%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/zkxx.xyz\/index.php\/2023\/02\/08\/win32%e5%92%8cvc%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%b1%bb%e5%9e%8b\/","title":{"rendered":"Win32\u548cVC++\u4e2d\u7684\u5404\u79cd\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u7c7b\u578b"},"content":{"rendered":"\n<p>\u5728\u4ecec\u5230c++\u7684\u5b66\u4e60\u8fc7\u7a0b\u4e2d\uff0c\u4ec5\u4ec5\u4e86\u89e3\u5230stl\u6807\u51c6\u6a21\u677f\u5e93\u4e2d\u7684string\u3001wstring\u7c7b\u578b\uff0c\u5728\u5b66\u4e60windows\u7a0b\u5e8f\u5f00\u53d1\u548cMFC\u6846\u67b6\u7684\u65f6\u5019\uff0c\u4e86\u89e3\u5230\u4e86wchar\u3001tchar\u3001LPWSTR\u3001LPCSTR\u3001LPCWSTR\u3001LPTSTR\u7b49\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u7c7b\u578b\u3002\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b\u4ed6\u4eec\u7684\u4ecb\u7ecd\u3001\u7528\u6cd5\u548c\u76f8\u4e92\u8f6c\u6362\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u9996\u5148\u4ecb\u7ecd\u4e00\u4e0bwchar\u548ctchar<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">wchar<\/h4>\n\n\n\n<p>Windows\u4e3a\u4e86\u6d88\u9664\u5404\u7f16\u8bd1\u5668\u7684\u5dee\u522b\uff0c\u91cd\u65b0\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6570\u636e\u7c7b\u578b\uff0c\u4f60\u63d0\u5230\u4e86\u53e6\u5916\u51e0\u4e2a\u7c7b\u578b\u90fd\u662f\u8fd9\u6837\u3002CHAR\u4e3a\u5355\u5b57\u8282\u5b57\u7b26\u3002\u8fd8\u6709\u4e2aWCHAR\u4e3aUnicode\u5b57\u7b26\uff0c\u5373\u4e0d\u8bba\u4e2d\u82f1\u6587\uff0c\u6bcf\u4e2a\u5b57\u6709\u4e24\u4e2a\u5b57\u8282\u7ec4\u6210\u3002\u5b83\u5b9e\u9645\u5b9a\u4e49\u5728&lt;string.h&gt;\u91cc\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n typedef unsigned short wchar_t\u3002\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">\u4e0b\u9762\u518d\u770b\u770bTCHAR<\/h4>\n\n\n\n<p>\u5982\u679c\u5e0c\u671b\u540c\u65f6\u4e3aANSI\u548cUnicode\u7f16\u8bd1\u7684\u6e90\u4ee3\u7801\uff0c\u90a3\u5c31\u8981include &lt;TChar.h&gt;\u3002TCHAR\u662f\u5b9a\u4e49\u5728\u5176\u4e2d\u7684\u4e00\u4e2a\u5b8f\uff0c\u901a\u8fc7\u4f60\u662f\u5426\u5b9a\u4e49\u4e86_UNICODE\u5b8f\u800c\u5b9a\u4e49\u6210char\u6216\u8005wchar_t\u3002\u5982\u679c\u5f53\u524d\u7f16\u8bd1\u65b9\u5f0f\u4e3aANSI(\u9ed8\u8ba4)\u65b9\u5f0f\uff0cTCHAR\u7b49\u4ef7\u4e8eCHAR\uff0c\u5982\u679c\u4e3aUnicode\u65b9\u5f0f\uff0cTCHAR\u7b49\u4ef7\u4e8eWCHAR\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u76f8\u5173\u7528\u6cd5<\/h4>\n\n\n\n<p>wchar_t\u548ctchar\u90fd\u6709\u81ea\u5df1\u7684\u5b57\u7b26\u4e32\u51fd\u6570\uff0c\u4e0d\u80fd\u4f7f\u7528strcpy\u8fd9\u7c7bANSI C\u5b57\u7b26\u4e32\u51fd\u6570\u3002\u5fc5\u987b\u4f7f\u7528wcs\u524d\u7f00\u7684\u51fd\u6570\uff0c\u4f8b\u5982wcscpy\u3002\u4e3a\u4e86\u8ba9\u7f16\u8bd1\u5668\u8bc6\u522bUnicode\u5b57\u7b26\u4e32\uff0c\u5fc5\u987b\u4ee5\u5728\u524d\u9762\u52a0\u4e00\u4e2a\u201cL\u201d,\u4f8b\u5982:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nwchar_t *szTest=L\"This is a Unicode string.\";\n<\/pre><\/div>\n\n\n<p>TCHAR\u4e5f\u4e0d\u80fd\u4f7f\u7528ANSI\u7684strXXX\u51fd\u6570\u6216\u8005Unicode\u7684wcsXXX\u51fd\u6570\u4e86\uff0c\u5fc5\u987b\u4f7f\u7528TChar.h\u4e2d\u5b9a\u4e49\u7684_tcsXXX\u51fd\u6570\u3002\u53e6\u5916\uff0c\u4e3a\u4e86\u89e3\u51b3\u521a\u624d\u63d0\u5230\u5e26\u201cL\u201d\u7684\u95ee\u9898\uff0cTChar.h\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5b8f\uff1a\u201c_TEXT\u201d\u3002<\/p>\n\n\n\n<p>&nbsp;\u4ee5strcpy\u51fd\u6570\u4e3a\u4f8b\u5b50\uff0c\u603b\u7ed3\u4e00\u4e0b:<br>&nbsp;.\u5982\u679c\u4f60\u60f3\u4f7f\u7528ANSI\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8bf7\u4f7f\u7528\u8fd9\u4e00\u5957\u5199\u6cd5\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n char szString&#x5B;100];\n strcpy(szString,\"test\");\n<\/pre><\/div>\n\n\n<p>&nbsp;.\u5982\u679c\u4f60\u60f3\u4f7f\u7528Unicode\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8bf7\u4f7f\u7528\u8fd9\u4e00\u5957\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n wchar_t szString&#x5B;100];\n wcscpyszString,L\"test\");\n<\/pre><\/div>\n\n\n<p>&nbsp;.\u5982\u679c\u4f60\u60f3\u901a\u8fc7\u5b9a\u4e49_UNICODE\u5b8f\uff0c\u800c\u7f16\u8bd1ANSI\u6216\u8005Unicode\u5b57\u7b26\u4e32\u4ee3\u7801\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n TCHAR szString&#x5B;100];\n _tcscpy(szString,_TEXT(\"test\"));\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">LPWSTR\u3001LPCSTR\u3001LPCWSTR\u3001LPTSTR<\/h4>\n\n\n\n<p>LPCSTR\u662f\u4e00\u4e2a\u6307\u5411\u4ee5&#8217;\\0&#8217;\u7ed3\u5c3e\u7684\u5e38\u91cf\u5b57\u7b26\u7684\u6307\u9488\u3002<\/p>\n\n\n\n<p>LPWSTR\u662f\u4e00\u4e2a\u6307\u5411wchar_t\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6307\u9488\u3002<\/p>\n\n\n\n<p>LPCWSTR\u662f\u4e00\u4e2a\u6307\u5411unicode\u7f16\u7801\u5b57\u7b26\u4e32\u768432\u4f4d\u6307\u9488\uff0c\u6240\u6307\u5411\u5b57\u7b26\u4e32\u662fwchar\u578b\uff0c\u800c\u4e0d\u662fchar\u578b\u3002\u5b83\u7684\u58f0\u660e\u5982\u4e0b:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\ntypedef const wchar_t* LPCWSTR;\n<\/pre><\/div>\n\n\n<p>LPSTR\u662f\u4e00\u4e2a\u6307\u5411\u4ee5NULL(\u2018\\0\u2019)\u7ed3\u5c3e\u768432\u4f4dANSI\u5b57\u7b26\u6570\u7ec4\u6307\u9488\uff0cLPWSTR\u662f\u4e00\u4e2a\u6307\u5411\u4ee5NULL\u7ed3\u5c3e\u768464\u4f4d\u53cc\u5b57\u8282\u5b57\u7b26\u6570\u7ec4\u6307\u9488\u3002\u90fd\u662f\u4ee5\u96f6\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u6307\u9488\uff0c\u76f8\u5f53\u4e8eCHAR *<\/p>\n\n\n\n<p>\u8fd9\u4e9b\u7c7b\u578b\u7684\u6765\u6e90\u90fd\u662f\u7f29\u5199\uff1a<br>L\u6765\u81ealong\uff0c\u6307\u957f\u7684\uff1b<br>P\u662fpointer\uff0c\u4ee3\u8868\u6307\u9488\uff1b<br>LP\uff1a\u957f\u6307\u9488\uff08long pointer\uff09\uff0c\u8fd9\u662f\u4e3a\u4e86\u517c\u5bb9Windows 3.1\u7b4916\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u9057\u7559\u4e0b\u6765\u7684\uff0c\u5728win32\u4e2d\u4ee5\u53ca\u5176\u4ed6\u768432\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0clong\u6307\u9488\u548cnear\u6307\u9488\u53cafar\u4fee\u9970\u7b26\u90fd\u662f\u4e3a\u4e86\u517c\u5bb9\u7684\u4f5c\u7528\uff0c\u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u3002\u5373win32\u4e2d\uff0clong\uff0cnear\uff0cfar\u6307\u9488\u4e0e\u666e\u901a\u6307\u9488\u6ca1\u6709\u533a\u522b\uff0cLP\u4e0eP\u662f\u7b49\u6548\u7684\uff1b<br>T\uff1awin32\u73af\u5883\u4e2d\u6709\u4e00\u4e2a_T\u5b8f\uff0c\u7528\u6765\u6807\u8bc6\u5b57\u7b26\u662f\u5426\u91c7\u7528Unicode\u7f16\u7801\uff08\u4e24\u5b57\u8282\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff09\uff0c\u82e5\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u4e86Unicode\uff0c\u8be5\u5b57\u7b26\/\u5b57\u7b26\u4e32\u88ab\u4f5c\u4e3aUnicode\u5b57\u7b26\u4e32\uff0c\u5426\u5219\u5c31\u662f\u6807\u51c6\u7684ANSI\uff08\u5355\u5b57\u8282\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff09\u5b57\u7b26\u4e32\u3002<br>C\u7684\u8bdd\u662fconst\uff0c\u8bf4\u660e\u662f\u4e2a\u5e38\u91cf\uff1b<br>W\u5c31\u662fwide char\uff08wchar\uff09\uff0c\u6307\u7684\u662f\u5bbd\u5b57\u7b26\uff1b<br>STR\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662fstring\u5b57\u7b26\u4e32\u5566\uff01<\/p>\n\n\n\n<p>\u8fd9\u4e9b\u5b57\u6bcd\u4e92\u76f8\u7ec4\u5408\uff0c\u5c31\u6784\u6210\u4e86\u8fd9\u4e9b\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6765\u9009\u7528\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u76f8\u4e92\u8f6c\u6362<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>cstring \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* cstring \u8f6c string *\/\nCString cs(_T(\"cs\")); \nstring s; \ns = (LPCSTR)(CStringA)(cs); \n\/* CString\u8f6c\u6362\u6210LPCWSTR\u3001LPWSTR\u3001LPCSTR\u3001LPSTR *\/\n\/\/VS2005\u4e2dCString\u5df2\u7ecf\u6539\u4e3a\u5bbd\u5b57\u7b26\u578b\nLPWSTR lpstr = (LPWSTR)(LPCWSTR)str; \nLPCSTR lpcstr = (LPCSTR)(LPCWSTR)str; \nLPSTR lpcstr = (LPSTR)(LPCWSTR)str; \n\/* CString\u8f6c\u6362\u6210char* \u3001TCHAR* *\/\nchar* p = (char*)str.GetBuffer(); \/\/\u65b9\u6cd51\nchar* p = (LPSTR)(LPCTSTR)str; \/\/\u65b9\u6cd52\nTCHAR* pw = str.GetBuffer();\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>string \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* string \u8f6c cstring *\/\nstring s =&quot;Hello World!\u4e2d\u56fd&quot;; \/\/\u65b9\u6cd51 \nCString cs(s.c_str()); \/\/\u65b9\u6cd52\uff0c\u7528c_str()\u786e\u5b9e\u6bd4data()\u8981\u597d CString.format(\u201d%s\u201d, string.c_str());\n\/* string \u8f6c lpcstr *\/\nstd::string a=&quot;abc&quot;;\nLPCSTR str = a.c_str();\n\/* string\u8f6c\u6362\u4e3aLPWSTR *\/\nwstring widstr&lt;em&gt;; \nstd:string s(&quot;DanTeng&quot;);\nwidstr = std::wstring(s.begin(), s.end());\nlvItem.pszText=(LPWSTR)widstr.c_str();\n\/* string\u8f6c\u6362\u4e3aint\u3001float *\/\n\/\/\u53ef\u4ee5\u4f7f\u7528atoi,atof,atol\u7b49\u51fd\u6570\u6765\u5b8c\u6210\u3002\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>LPCWSTR \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* LPCWSTR\u8f6c\u6362\u6210CString *\/\nLPCWSTR lpcwStr = L\"TestWStr\"; \nCString str(lpcwStr);\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>LPWSTR \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* LPWSTR \u8f6c\u6362\u6210LPWSTR *\/ \nLPWSTR lpwstr = (LPCSTR)lpstr; \nlpwstr = (LPWSTR)lpcstr;\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>LPCSTR \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* LPCSTR \u8f6c\u6362\u6210CString *\/\nLPCSTR lpcStr = (LPCSTR)str; \n\/* LPWSTR \u8f6c\u6362\u6210LPWSTR *\/\nLPWSTR lpwstr = (LPCSTR)lpstr;\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>LPSTR \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* LPSTR \u8f6c\u6362\u6210CString *\/\nLPSTR lpStr = L\"TestStr\"; \nCString str(lpStr); \n\/* LPSTR \u8f6c\u6362\u6210LPCSTR\u3001LPWSTR \u3001LPCWSTR *\/\nLPCSTR lpcstr = lpstr; \nLPWSTR lpwstr = (LPWSTR)lpstr; \nLPCWSTR lpcwstr = (LPCWSTR)lpstr;\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>char* \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* char* \u8f6c\u6362\u6210CString *\/\nchar* p = \"test\"; \/\/\u65b9\u6cd51 \nCString str = (\"%s\",p); \/\/\u65b9\u6cd52\nCString.format(\u201d%s\u201d, char*); \n\/* char* \u8f6c\u6362\u6210string*\/\nstring s(char *); \/\/\u53ea\u80fd\u521d\u59cb\u5316\uff0c\u975e\u521d\u59cb\u5316\u7684\u5730\u65b9\u8fd8\u662f\u7528assign().\n\/* char* \u8f6c\u6362\u6210LPSTR\u3001LPCSTR *\/\nchar *p; \nLPSTR lpstr = p; \nLPCSTR lpcstr = p; \n\/* char* \u8f6c\u6362\u6210WCHAR *\/\nwchar_t ws&#x5B;100]; \nswprintf(ws, 100, L\"%hs\", \"ansi string\");\n<\/pre><\/div>\n\n\n<p>\/* char* \u8f6c\u6362\u6210LPCWSTR *\/<br><a rel=\"noreferrer noopener\" href=\"http:\/\/www.jb51.net\/article\/101978.htm\" target=\"_blank\">\u53c2\u8003\uff1aC++\u4e2dchar*\u8f6c\u6362\u4e3aLPCWSTR\u7684\u89e3\u51b3\u65b9\u6848<\/a><\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>TCHAR * \/WCHAR* \u8f6c\u6362\u4e3a *<\/strong><\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* TCHAR* \u8f6c\u6362\u6210char* *\/\np = (char*)sex; \n\/* WCHAR* \u8f6c\u6362\u6210TCHAR* *\/\npw = (WCHAR*)name; \n\/* WCHAR* \u8f6c\u6362\u6210char* *\/\nchar output&#x5B;256]; \nWCHAR* wc = L\"Hellow World\"; \nsprintf(output, \"%ws\", wc );\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u5728\u5f53\u524d\u7248\u672cLPCSTR\u548cLPSTR\u6ca1\u533a\u522b\uff0c\u5373\u3002<br>LPCSTR, A 32-bit pointer to a constant character string.&nbsp;&nbsp;&nbsp;<br>\u5e38\u91cf\u6307\u9488\uff0c\u4e00\u822c\u7528\u4e8e\u53c2\u6570\u4f20\u9012\u548c\u56fa\u5b9a\u5b57\u7b26\u4e32&nbsp;&nbsp;&nbsp;<br>LPSTR, A 32-bit pointer to a character string.&nbsp;&nbsp;&nbsp;<br>\u666e\u901a\u6307\u9488\uff0c\u4e00\u822c\u7528\u4e8e\u5b57\u7b26\u4e32\u64cd\u4f5c&nbsp;&nbsp;&nbsp;<br>\u6839\u636eDBCS\u6216Unicode \u81ea\u52a8\u9009\u62e9char\u6216wchar_t\u7c7b\u578b\uff0c\u7531\u5b9a\u4e49\u7684\u5b8f_UNICODE\u51b3\u5b9a&nbsp;&nbsp;&nbsp;<br>LPCTSTR, A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.&nbsp;&nbsp;&nbsp;<br>LPTSTR, A 32-bit pointer to a character string that is portable for Unicode and DBCS.<\/p>\n\n\n\n<p>\u4e00\u4e2a\u8f6c\u6362CString \u7684\u4f8b\u5b50\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString str = \"ABC\";\nLPCTSTR ptr1 = new TCHAR&#x5B;str.GetLength()+1];\nptr1 = (LPCTSTR) str.GetBuffer();\nLPTSTR ptr2 = new TCHAR&#x5B;str.GetLength()+1];\nptr2 = (LPTSTR) str.GetBuffer();\nLPSTR ptr3 = new char&#x5B;str.GetLength()+1];\nptr3 = (LPSTR) str.GetBuffer();\nLPCSTR ptr4 = new char&#x5B;str.GetLength()+1];\nptr4 = (LPCSTR) str.GetBuffer();\n<\/pre><\/div>\n\n\n<p>\u53e6\u5916\uff0c\u8981\u6ce8\u610f\u9009\u7528\u7684\u51fd\u6570\u4e5f\u8981\u548cstring\u7c7b\u578b\u4e00\u81f4\u3002\u6bd4\u5982\u4e0b\u9762\uff1atmp1=144,tmp2=1,\u56e0\u4e3asLastChan\u4e3a\u5bbd\u5b57\u8282\uff0c\u5b58\u50a8\u4e3a310034003400, atoi\u51fd\u6570\u9047\u5230\u7b2c\u4e00\u4e2a&#8221;00&#8243;\u5c31\u4f1a\u7ed3\u675f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString sLastChan = _T(\"144\");\nint t,tmp2;\nt=_tstoi((TCHAR*)sLastChan.GetBuffer(sLastChan.GetLength()));\ntmp2=atoi((char*)sLastChan.GetBuffer(sLastChan.GetLength()));\n<\/pre><\/div>\n\n\n<p>\u7531\u4e8eWin32 API\u6587\u6863\u7684\u51fd\u6570\u5217\u8868\u4f7f\u7528\u51fd\u6570\u7684\u5e38\u7528\u540d\u5b57\uff08\u4f8b\u5982\uff0c SetWindowText&#8221;\uff09\uff0c\u6240\u6709\u7684\u5b57\u7b26\u4e32\u90fd\u662f\u7528TCHAR\u6765\u5b9a\u4e49\u7684\u3002\uff08\u9664\u4e86XP\u4e2d\u5f15\u5165\u7684\u53ea\u9002\u7528\u4e8eUnicode\u7684API\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">LPTSTR \u8f6c\u6362\u6210 CString<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">(1)\u76f4\u63a5\u8d4b\u503c<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString strText;\nLPTSTR lpszText = _T(&quot;LPTSTR &gt;&gt; CString&quot;);\nstrText = lpszText;\nMessageBox(NULL, strText, _T(&quot;\u6807\u9898&quot;), MB_ICONASTERISK|MB_TASKMODAL|MB_OK);\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">(2)CString::Format()\u683c\u5f0f\u5316<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString strText;\nLPTSTR lpszText = _T(&quot;LPTSTR &gt;&gt; CString&quot;);\nstrText.Format(_T(&quot;%s&quot;), lpszText );\n::MessageBox(NULL, strText, _T(&quot;\u6807\u9898&quot;), MB_ICONASTERISK|MB_TASKMODAL|MB_OK );\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">CString \u8f6c\u6362\u6210 LPTSTR<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">(1)\u5f3a\u5236\u8f6c\u6362<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString strText(_T(\"This is a test\"));\nLPTSTR lpszText =(LPTSTR)(LPCTSTR)strText;\n::MessageBox(NULL, lpszText, _T(\"\u6807\u9898\"), MB_ICONASTERISK|MB_TASKMODAL|MB_OK);\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">(2)\u4f7f\u7528lstrcpy()<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString strText(\"This is a test\");\nLPTSTR lpszText = new TCHAR&#x5B;strText.GetLength()+1];\nlstrcpy(lpszText, strText);\n::MessageBox(NULL, lpszText, _T(\"\u6807\u9898\"), MB_ICONASTERISK|MB_TASKMODAL|MB_OK);\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">(3)\u4f7f\u7528CString::GetBuffer()<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nCString strText(_T(\"This is a test \"));\nLPTSTR lpszText = strText.GetBuffer();\nstrText.ReleaseBuffer();\n::MessageBox( NULL, lpszText, _T(\"\u6807\u9898\"),MB_ICONASTERISK|MB_TASKMODAL|MB_OK );\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* char * \u8f6c\u6362\u6210 CString\nchar chArray&#x5B;] = \"This is a test\";\nchar * p = \"This is a test\";\nCString theString = chArray;\ntheString.Format(_T(\"%s\"), chArray);\ntheString = p;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* CString\u8f6c\u6362\u6210char*\nCString theString( \"This is a test\" );\nLPTSTR lpsz = new TCHAR&#x5B;theString.GetLength()+1];\n_tcscpy(lpsz, theString);\n\/\/ \u6216\nCString s(_T(\"Char test \"));\nLPTSTR p = s.GetBuffer();\u00a0\nLPTSTR dot = strchr(p, ''.'');\n\/\/ \u5728\u8fd9\u91cc\u6dfb\u52a0\u4f7f\u7528p\u7684\u4ee3\u7801\nif(p != NULL)\n*p = _T('');\ns.ReleaseBuffer();\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>c++\u4e2dLPTSTR<\/h2>\n\n\n\n<p>\u7f16\u8f91<\/p>\n\n\n\n<p>LPCTSTR\uff0cLPWSTR, PTSTR, LPTSTR\uff0cwchar_t\u533a\u522b<\/p>\n\n\n\n<p>L\u8868\u793along\u6307\u9488\uff0c\u8fd9\u662f\u4e3a\u4e86\u517c\u5bb9Windows 3.1\u7b4916\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u9057\u7559\u4e0b\u6765\u7684\uff0c\u5728win32\u4e2d\u4ee5\u53ca\u5176\u4ed6\u768432\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c long\u6307\u9488\u548cnear\u6307\u9488\u53cafar\u4fee\u9970\u7b26\u90fd\u662f\u4e3a\u4e86\u517c\u5bb9\u7684\u4f5c\u7528\uff0c\u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u3002\u5373win32\u4e2d,long,near,far\u6307\u9488\u4e0e\u666e\u901a\u6307\u9488\u6ca1\u6709\u533a\u522b\uff0cLP\u4e0eP\u662f\u7b49\u6548\u7684\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4e0b\u9762\u5217\u51fa\u4e00\u4e9b\u5e38\u7528\u7684typedefs\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>\u7c7b\u578b<\/td><td>MBCS<\/td><td>Unicode<\/td><\/tr><tr><td>WCHAR <\/td><td>wchar_t<\/td><td>wchar_t<\/td><\/tr><tr><td>LPSTR <\/td><td>char*<\/td><td>char*<\/td><\/tr><tr><td>LPCSTR <\/td><td>const char*<\/td><td>const char*<\/td><\/tr><tr><td>LPWSTR<\/td><td>wchar_t*<\/td><td>wchar_t*<\/td><\/tr><tr><td>LPCWSTR <\/td><td>const wchar_t*<\/td><td>const wchar_t*<\/td><\/tr><tr><td>TCHAR <\/td><td>char <\/td><td>wchar_t<\/td><\/tr><tr><td>LPTSTR <\/td><td>TCHAR*(\u6216char*)<\/td><td>TCHAR* (\u6216wchar_t*)<\/td><\/tr><tr><td>LPCTSTR <\/td><td>const TCHAR*(\u6216const char*)<\/td><td>const TCHAR*(\u6216const wchar_t*)<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">\u5e38\u7528\u7684typedefs<\/figcaption><\/figure>\n\n\n\n<p>\u6240\u4ee5\u4e3a\u63d0\u9ad8\u53ef\u79fb\u690d\u6027\uff0c\u5b9a\u4e49\u5b57\u7b26\u4e32\u65f6\u7528TCHAR\uff0c\u8f6c\u5316\u4e3aUNICODE\u65f6\u7528_T\u800c\u4e0d\u7528L\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4ecec\u5230c++\u7684\u5b66\u4e60\u8fc7\u7a0b\u4e2d\uff0c\u4ec5\u4ec5\u4e86\u89e3\u5230stl\u6807\u51c6\u6a21\u677f\u5e93\u4e2d\u7684string\u3001wstring\u7c7b\u578b\uff0c\u5728\u5b66\u4e60window [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":13,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}