Win32 API problem in VC++2008 Express

Started by
2 comments, last by boogyman19946 13 years, 9 months ago
I'm facing a weird problem that I can't seem to find the answer to and it basically involves switching from GCC to the Visual Studio 2008 compiler.

Seemingly, the GCC implementation of the API differs from the VC++ mainly in that GCC uses normal (simple char) for string arguments like in MessageBox and refuses to compile when using wide strings. This is somewhat silly because VC++ is the exact opposite; it refuses to compile if wide strings aren't used. That's just weird.

Either way, I decided to stick with the VS08 because it has a nice IDE and I can plug in the resource editor, so I have everything available at hand. But I'm encountering a problem with my text drawing functions in the back buffer.

Here's a picture of the numbers being drawn properly when compiled with GCC:


And here is a picture of the numbers drawn when compiled with VS08:


The functions are pretty much the same with some differences.

GCC version:
bool BackBuffer::DrawText(std::string argStr, int xPos, int yPos){	if (argStr.empty()) {		MessageBox(0, "String is empty", "Error!", MB_OK);		return 0;	}	TextOut(mhDC, xPos, yPos, argStr.c_str(), argStr.length());		return 1;}


and the VS08 version:
bool BackBuffer::DrawText(std::string argStr, int xPos, int yPos){	if (argStr.empty()) {		MessageBox(0, L"String is empty", L"Error!", MB_OK);		return 0;	}	TextOut(mhDC, xPos, yPos, (LPCWSTR)argStr.c_str(), argStr.length())		return 1;}


I've tried looking through a debugger since VS08 provides one, but everything seems to be fine. I have no idea what might be causing this problem. Can anyone help me out? Thanks!

Yo dawg, don't even trip.

Advertisement
I could be wrong, but I reckon the problem is here -> (LPCWSTR)argStr.c_str(). If you look in the MSDN under string formats or similar there a some string type conversion functions. I'd try the one that converts std::string into wc_string and feed that in, that could rule out any dramas the casting might be causing.
The high cost of living hasn't affected its popularity.
Short answer: get rid of the cast and going to your project properties and change the character set from Unicode to multibyte.
Quote:Original post by SiCrane
Short answer: get rid of the cast and going to your project properties and change the character set from Unicode to multibyte.


Excellent :D That worked, thanks a lot!

Yo dawg, don't even trip.

This topic is closed to new replies.

Advertisement