問題:
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(27) : error C2440: “=”: 無法從“const char [14]”轉換爲“LPCWSTR”
1> 與指向的類型無關;轉換要求 reinterpret_cast、C 樣式轉換或函數樣式轉換
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(35) : error C2664: “CreateWindowExW”: 不能將參數 2 從“const char [14]”轉換爲“LPCWSTR”
1> 與指向的類型無關;轉換要求 reinterpret_cast、C 樣式轉換或函數樣式轉換
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(65) : error C2664: “MessageBoxW”: 不能將參數 2 從“char [20]”轉換爲“LPCWSTR”
1> 與指向的類型無關;轉換要求 reinterpret_cast、C 樣式轉換或函數樣式轉換
解決:
MessageBox(hwnd,szChar,"char",0);
MessageBox 在2008中定義爲 MessageBoxW W指的是寬字節(也叫UNICODE),有3種方法可解決
①用函數MessageBoxA
②在內容前加上TEXT(對變量無效),如MessageBox(hwnd,szChar,TEXT("char"),0);
③在項目屬性->常規中,把Uicode改成多字符段。
PS:在2008中,很多函數的返回值都是寬字節的,所以不一定要用MessageBoxA
在MSDN上可以查到用寬字節的函數和同樣功能普通函數的名稱。
在6.0中沒用寬字節
轉載自:http://apps.hi.baidu.com/share/detail/16474815