http://blog.csdn.net/ahjxly/article/details/8494217
http://blog.csdn.net/b_h_l/article/details/7581519
http://blog.chinaunix.net/uid-339069-id-3402668.html
沒有定義UNICODE,所以它里面的字符串就是簡單用" "就行了,創建工程的時候包含了UNICODE定義,就必須對TCHAR和char進行轉換。
void TcharToChar(const TCHAR * tchar, char * _char) { int iLength; //獲取字節長度 iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL); //將tchar值賦給_char WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL); } void CharToTchar(const char * _char, TCHAR * tchar) { int iLength; iLength = MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, NULL, 0); MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, tchar, iLength); }
表明 TCHAR 與 WCHAR 屬同一類型
char szA[100]; // ANSI string buffer
WCHAR szW[100]; // Unicode string buffer
// Normal sprintf:all strings are ANSI
sprintf(szA, "%s","ANSI Str");
// Converts Unicode string to ANSI
sprintf(szA,"%S",L"Unicode Str");
// Normal swprintf:all strings are Unicode
swprintf(szW,L"%s",L"Unicode Str");
// Converts ANSI string to Unicode
swprintf(szW,L"%S", "ANSI Str");
注意:大寫S 和小寫s 的使用