Jump to content
  • Advertisement
Sign in to follow this  
boogyman19946

Win32 API problem in VC++2008 Express

This topic is 2951 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 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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Short answer: get rid of the cast and going to your project properties and change the character set from Unicode to multibyte.

Share this post


Link to post
Share on other sites
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!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!