# GDI+ DrawString Invalid Parameter

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

## Recommended Posts

Hello,

I am about to create a SpriteFont generator. Therefore I wanted to utilize GDI+ to draw all the characters I need to a bitmap and then use the data as a texture.

Proplem is, that every DrawString call i make results in an invalid parameter status. However for testing reasons I pretty much opy pasted the msdn code sample and still got an invalid exception.

I do check all the results when I create or maipulate objects and until the DrawString all results as Ok.

Here is the code:

// Create the font
Gdiplus::Font font (_Name.c_str (), _Size, _Style, Gdiplus::Unit::UnitPixel);
GdiPlusCall (font.GetLastStatus ());

// Solid white brush for text rendering
Gdiplus::SolidBrush brush (Gdiplus::Color (255, 255, 255, 255));
GdiPlusCall (brush.GetLastStatus ());

// Setup bitmap and graphics object for rendering the texture
Gdiplus::Bitmap texBitmap (texWidth, _TexHeight, PixelFormat32bppARGB);
GdiPlusCall (texBitmap.GetLastStatus ());

Gdiplus::Graphics texGraphics (&texBitmap);
GdiPlusCall (texGraphics.GetLastStatus ());

GdiPlusCall (texGraphics.Clear (Gdiplus::Color (0, 255, 255, 255)));
GdiPlusCall (texGraphics.SetCompositingMode (Gdiplus::CompositingMode::CompositingModeSourceCopy));

// Just for test reasons
WCHAR asd[2];

asd[0] = 'A';
asd[1] = '\0';

Gdiplus::Status s = texGraphics.DrawString (asd, 1, &font, Gdiplus::PointF (0.0f, 0.0f), &brush);

// s == Gdiplus::Status::InvalidParameter - but why????


where GdiPlusCall is a makro that returns false, if the result is not Ok.

##### Share on other sites

Set length to -1, instead of 1. The proper number to pass in for you would be 2, it expects the number of characters, not string length.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms535993(v=vs.85).aspx

Integer that specifies the number of characters in the string array. The length parameter can be set to –1 if the string is null terminated.

##### Share on other sites

Allready tried that, neither -1 nor 2 works properly. I still get the InvalidParameter result.

Update:

So far I have tried all possible overloads of DrawString with the same result... However other draw calls (like DrawRectangle) work just fine. Which leads me to belief that there is somthing messed up with the font. Is there a posibility to retrieve further information on the error of that function call?

Edited by Wh0p

##### Share on other sites

Ok, sorry for the sort of multi post but i see this issue as resolved now.

Problem is, that on Win8 Graphics.DrawString and Graphics.SetCompositingMode(CompositingModeSourceCopy) don't go along with each other.

I think this is a known issue (http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/7f02b531-529d-4940-a220-cde46e61e88f/windows-8-garbled-text-with-gdi-graphicsdrawstring) but noone cares at MS...

• 13
• 18
• 29
• 11
• 27