Click here to Skip to main content
15,876,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I've got a VS2005 MFC program with a GDI+ user-drawn display which runs perfectly under Windows 7. If I run it under XP Mode, each text string has a square box after it, which looks like a missing font character, however it uses Ariel, which is installed. The MFC exe isn't Unicode.

Any ideas if it's a problem with GDI+ under XP or XP Mode, or something else?


The first thing to do is examine the string you are trying to display in order to see exactly what the last character is. That should give you a clue as to what is going wrong, possibly a bug in your code.
Share this answer
hairy_hats 9-Jan-12 6:09am    
The same text strings worked fine with GDI under XP Mode, and they work fine under Windows 7 using GDI+, so I don't think that is the problem. I suspect it's something to do with GDI+ and XP.
Richard MacCutchan 9-Jan-12 6:16am    
You should still look at the actual content and see what this character is and why it is being displayed erroneously. Guessing what might be happening is not the same thing as using the debugger to check the facts.
hairy_hats 9-Jan-12 7:48am    
I have just checked once again to make sure, and as I said, the text strings sent to the Graphics object are identical (zero-terminated wchar_t strings).
Richard MacCutchan 9-Jan-12 8:10am    
A bit of a mystery then. I've never seen a situation like this and have used GDI+ under XP, Vista and Windows 7.
hairy_hats 9-Jan-12 8:35am    
Problem solved! Windows 7 ignores the string's zero terminator (or at least, renders it invisibly), but XP renders it as a square box. Reducing the string length passed to the rendering function by one fixed it.
The string length passed to the Graphics::DrawString function shouldn't include the zero terminator.
Share this answer
Richard MacCutchan 9-Jan-12 11:45am    
The same as with any other Windows function that takes a string and its length.
hairy_hats 9-Jan-12 12:06pm    
mbstowcs_s returns the number of characters that were converted, *including* the null terminator. My mistake was in passing that length to Graphics::DrawString, but as I said before, Windows 7 rendered it correctly.
Richard MacCutchan 9-Jan-12 12:19pm    
Windows 7 rendered it correctly.
Never rely on Microsoft.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900