Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with CreateWindow(), MessageBox() and UnregisterClass()

Started by mits Jun 30, 2006 at 1:21 PM 2 replies 2.2k views
Original Post
mits
mits
How's possible to have this : mHwnd = CreateWindow("Windowclass", "Good", mstyle, mXpos, mYpos, mWidth, mHeight, NULL, NULL, mHinstance, NULL); which is perfectly legal , as the example about CreateWindow() in MSDN says : hwnd = CreateWindow("MainWClass", "Sample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND) NULL, (HMENU) NULL, hinstance, (LPVOID) NULL); and then to have an error like this? error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR' I have also this : MessageBox(NULL, "Could not create window", "Error", MB_OK); and then this error : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR' I can’t even unregister my window class like this: UnregisterClass("Windowclass", mHinstance); Because I get the error : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR' No need to mention that when I setup my window class and write this: mWcex.lpszClassName = "Windowclass"; I get an error again: error C2440: '=' : cannot convert from 'const char [12]' to 'LPCWSTR' I can't figure out what's wrong. Please if anyone has any idea.... Thanks in advance
yadango
yadango
add
#undef UNICODE
before your #include
or deselect Unicode from the property pages.
ApochPiQ
ApochPiQ
This is indeed a Unicode thing.

There are basically two options, the easy cop-out being to disable Unicode support for your code (right click your project in the project viewer, select Properties, and in the General section there is an option for the character set your program uses - it's probably set to Unicode at the moment; change it to Not Set). However, this isn't the best idea, because Unicode is becoming increasingly important, and you may as well learn how to support it now.

(BTW, I would recommend *against* the #undef UNICODE option - even though it may work, it's a lazy hack and might come back to bite you if you aren't careful later. Best not to get into that habit.)


Check out this article for some introductory pointers on writing Unicode-aware software.
Rattrap
Rattrap
Put the TEXT() macro around your literals.

mHwnd = CreateWindow(TEXT("Windowclass"), TEXT("Good"), mstyle, mXpos, mYpos, mWidth, mHeight, NULL, NULL, mHinstance, NULL);


And when need a string use TCHAR instead of char

so

TCHAR strWndClass = TEXT("Windowclass");
"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.