Search code examples
c++codeblockswxwidgets

C:B compiler issue with wxwidgets project


This is a newbie's question: When I created a wxWidgets frame project, and at the point that I need to add #include in a function, I had such compiler error:

C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HWND__* CreateDialog(HINSTANCE, LPCTSTR, HWND, DLGPROC)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|39|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateDialogParamW(HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HFONT__* CreateFont(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|70|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '14' to 'HFONT__* CreateFontW(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCWSTR)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HWND__* CreateWindow(LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|95|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateWindowExW(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HMENU__* LoadMenu(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|112|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HMENU__* LoadMenuW(HINSTANCE, LPCWSTR)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HWND__* FindText(LPFINDREPLACE)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|127|error: cannot convert 'LPFINDREPLACE {aka FINDREPLACEA*}' to 'LPFINDREPLACEW {aka FINDREPLACEW*}' for argument '1' to 'HWND__* FindTextW(LPFINDREPLACEW)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HICON__* LoadIcon(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|312|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HICON__* LoadIconW(HINSTANCE, LPCWSTR)'|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h||In function 'HBITMAP__* LoadBitmap(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-2.9.4\include\wx\msw\winundef.h|325|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HBITMAP__* LoadBitmapW(HINSTANCE, LPCWSTR)'|
P:\c++\codeblocks\UDP SOCKET COM\Communication.cpp||In function 'void ConnectUDP()':|
P:\c++\codeblocks\UDP SOCKET COM\Communication.cpp|7|warning: unused variable 's' [-Wunused-variable]|
||=== Build finished: 7 errors, 1 warnings (0 minutes, 1 seconds) ===|

Here are the codes:

#include <winsock2.h>
#include <wx/msgdlg.h> 
#include <wx/string.h>

void ConnectUDP(){

SOCKET s;
int result;

WSADATA wsaData;
//initialize winsock
result = WSAStartup(MAKEWORD(2,2), &wsaData);
if(result != NO_ERROR){
    wxMessageBox("WSAStartup failed with error: " + wxString::Format(wxT("%i"),result));
}
}

This only happens on c:b, I don't have problem with wxdev or vs2015


Solution

  • You seem to have a mismatch between UNICODE settings for wxWidgets and your own code, i.e. you just need to define UNICODE in your project options.

    Also do yourself a favour and stop using a 4 year old development version and switch to using either 3.1.0 or at least 3.0 (the latest is 3.0.2 right now).