Click here to Skip to main content
13,148,503 members (50,577 online)
Rate this:
Please Sign up or sign in to vote.
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?

Posted 8-Jan-12 23:49pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
viaducting 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.
viaducting 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.
viaducting 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.
Richard MacCutchan 9-Jan-12 9:26am
Interesting, I must try this out some time.
JackDingler 9-Jan-12 11:18am
Right, it's unsafe to assume that char 0 is a non-printable character.
Richard MacCutchan 9-Jan-12 11:43am
Hmm, I just realised what you said. The string length, if specified, is not supposed to include the terminating null, so it was your code that was in error.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The string length passed to the Graphics::DrawString function shouldn't include the zero terminator.
Richard MacCutchan 9-Jan-12 11:45am
The same as with any other Windows function that takes a string and its length.
viaducting 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 9 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100