错误 C2664:"HWND 无法将参数 2 从"lpctstr"转换为"lpcwstr" Visual Studio 2015



我正在使用wxWidgets 3.0.2和visual Studio 2015对wxWidgets非常陌生。给定错误的原因是什么,有些人说是因为包含的顺序,有些人说是因为unicode。所以我期待一个明确的答案。

C:wxWidgets-3.0.2includewx/msw/winundef.h(38): error C2664: 'HWND CreateDialogParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
 C:wxWidgets-3.0.2includewx/msw/winundef.h(38): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast`
C:wxWidgets-3.0.2includewx/msw/winundef.h(69): error C2664: 'HFONT CreateFontW(int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR)': cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR'
  C:wxWidgets-3.0.2includewx/msw/winundef.h(69): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:wxWidgets-3.0.2includewx/msw/winundef.h(95): error C2664: 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:wxWidgets-3.0.2includewx/msw/winundef.h(95): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:wxWidgets-3.0.2includewx/msw/winundef.h(111): error C2664: 'HMENU LoadMenuW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:wxWidgets-3.0.2includewx/msw/winundef.h(111): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:wxWidgets-3.0.2includewx/msw/winundef.h(311): error C2664: 'HICON LoadIconW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:wxWidgets-3.0.2includewx/msw/winundef.h(311): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:wxWidgets-3.0.2includewx/msw/winundef.h(324): error C2664: 'HBITMAP LoadBitmapW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:wxWidgets-3.0.2includewx/msw/winundef.h(324): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

您似乎正在用wxUSE_UNICODEUNICODE预处理器符号值的错误混合编译代码。最好能说明正在编译的内容(示例越小越好)以及所使用的编译器选项。在没有这些信息的情况下,我所能说的是,如果你只是在IDE的项目选项对话框的"常规"页面中将"字符集"设置为"使用Unicode",并且不做任何其他事情,那么所有内容都应该可以编译出来,没有任何问题。

当然,如果您已经编辑了include/wx/msw/setup.h文件,例如,在那里更改了wxUSE_UNICODE的值,则需要还原此文件。例如,请确保您使用的未修改的 wxWidgets源代码

正如这里所讨论的,这是由于一些Windows头文件被包含在Wx头文件之前(除非您确实像上面讨论的那样对Unicode进行了大量修改)。核对一下他们点的菜,你就没事了。

最新更新