Click to See Complete Forum and Search --> : Problems with first Win32... pls help!


jwcalifo
February 28th, 2006, 09:52 PM
Hello everyone!

I'm a newbie to windows programming, having migrated from Linux, and am having problems even with my Hello World app... Could someoen please tell me what I am doing wrong here... thanks!


#include <windows.h>

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd )
{
MessageBox( NULL, "I finally work!",
"Hello World", MB_OK | MB_ICONEXCLAMATION ) ;
}

The error says Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [16]' to 'LPCWSTR'

Thanks in advance!

golanshahar
March 1st, 2006, 01:25 AM
Looks like you are using Unicode build in that case change the code:


::MessageBox( NULL, _T("I finally work!"),_T("Hello World"), MB_OK | MB_ICONEXCLAMATION ) ;

// or

::MessageBox( NULL, L"I finally work!",L"Hello World", MB_OK | MB_ICONEXCLAMATION ) ;



Cheers

jwcalifo
March 1st, 2006, 03:42 AM
Hmm... unicode build eh? Is that the standard? Is there another mode I should use? I use VS2005. Thanks for the info! :)

jwcalifo
March 1st, 2006, 03:44 AM
My compiler cannot find the _T... :(

ovidiucucu
March 1st, 2006, 03:51 AM
My compiler cannot find the _T... :(
Help the compiler to find it. ;)
include <TCHAR.H>

UnfitElf
March 1st, 2006, 04:00 AM
If you are just beginning with WIN32 applications i would not worry about doing anything with unicode, its just tht bit of exta work that makes things more complex..

ovidiucucu
March 1st, 2006, 04:27 AM
If you are just beginning with WIN32 applications i would not worry about doing anything with unicode, its just tht bit of exta work that makes things more complex..
Yeah, sure, but making a habit from Using Generic-Text Mappings (http://msdn2.microsoft.com/en-us/library/7dzey6h6.aspx) (also definitions for generic international functions from TCHAR.H) even for a beginner is not bad.
Later, maybe he/she will work on a serious comercial application and if he/she will consider that "its just tht bit of exta work that makes things more complex" usually will ignore that.
One day, when the application is complex with tens/hundred of thousands lines of code, the boss comes and says "We have to deploy on Japanese market, ASAP!!!".
Then he/she will see indeed much much (usually unallocated in the development plan) extra work necessary.