K25125

I am trying to make a message box appear with the following code:

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

MessageBox(NULL,"Hello World!","My first windows app",MB_OK);

return 0;

}

with the windows header file. It's from a website, but the compiler says:

------ Build started: Project: ManlyTest, Configuration: Debug Win32 ------

Compiling...

Main.cpp

c:\users\MyUsername\documents\visual studio 2005\projects\PrjectName\ProjectName\main.cpp(8) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [13]' to 'LPCWSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Build log was saved at "file://c:\Users\MyUsername\Documents\Visual Studio 2005\Projects\ProjectName\ProjectName\Debug\BuildLog.htm"

ProjectName- 1 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can anybody help me out. I have SP1 and the PSDK on Windows Vista.



Re: Visual C++ Express Edition Message Box Error

Bite Qiu - MSFT

Try to add an 'L' before any string literal will eliminate this problem:

MessageBox(NULL,L"Hello World!",L"My first windows app",MB_OK);






Re: Visual C++ Express Edition Message Box Error

K25125

Now it says:

------ Build started: Project: Project, Configuration: Debug Win32 ------

Compiling...

Main.cpp

Linking...

Main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _WinMain@16

C:\Users\User\Documents\Visual Studio 2005\Projects\Project\Project.exe : fatal error LNK1120: 1 unresolved externals

Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2005\Projects\Project\Project\Debug\BuildLog.htm"

Project - 2 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========





Re: Visual C++ Express Edition Message Box Error

K25125

Never Mind, I fixed it...