Jump to content
  • Advertisement
Sign in to follow this  
Cable_pair

VS 2005 problem

This topic is 4321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to write a very simple windows program. The following code compiles and runs fine under VC++ 2003, but under vs2005 I get an error.
#define WIN32_LEAN_AND_MEAN	// trim down the libraries used

#include <windows.h>	// main windows header

// the main entry point to the program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	// show a very simple message box with the text "Hello, world!" displayed
	MessageBox(NULL, "\tHello, world!", "My First Windows Application", NULL);
	return 0;
}

Here's the error I get:
 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Does anyone know why VS2005 doesn't like this?

Share this post


Link to post
Share on other sites
Advertisement
VS2005 uses wide characters by default for Win32, a wide string looks like this:
L"contents"

The string type is std::wstring (a typedef for std::basic_string<wchar_t>) and the char type is wchar_t. You can also tell it to use ASCII characters again in your project options.

EDIT: You modify the character set here:
Project properties->Configuration properties->General->Character Set, set to "Use Multi-Byte Character Set"

Share this post


Link to post
Share on other sites
You can also use the TEXT() macro around the literal string. This will tac on the L if your are compiling using a wide character set or leave it off it you are using signle byte character set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!