954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cannot Compile Win32 Hello World

Okay, this just makes me feel stupid. I'm pretty good at programming for the console so I figured I would try a Win32 program. Apparently I'm stupid because I cannot even compile hello world. Heres the code I copy and pasted.

#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	
	MessageBox(NULL, "\tHello World!", "My first windows app", NULL);
	return 0;
}


I'm getting this error twice:

argument of type "const char *" is incompatible with parameter of type "LPCWSTR"


Can anyone help me get this working? I already tried google.

wade2462
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

char* is not a wide string, which is needed. There is a lot of help via google.

griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
 
argument of type "const char *" is incompatible with parameter of type "LPCWSTR"


See this codeproject article What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR etc?

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

I believe you need to change, in your project settings, that you're using a multi-byte character set instead of Unicode. That should solve your problem.

Spartan-S63
Newbie Poster
15 posts since Mar 2010
Reputation Points: 10
Solved Threads: 2
 
MessageBox(NULL, "\tHello World!", "My first windows app", NULL);

Change to

MessageBox(NULL, L"\tHello World!", L"My first windows app", NULL);
nbaztec
Posting Pro in Training
475 posts since May 2010
Reputation Points: 57
Solved Threads: 60
 
I believe you need to change, in your project settings, that you're using a multi-byte character set instead of Unicode. That should solve your problem.

Thank you this worked. Now I'm off to learn.

wade2462
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: