GDI Failure error from Borland C++ 5

Started by
3 comments, last by Alusair 21 years, 10 months ago
Hello. I''m somewhat new to game programming, having next to no experience with Windows programming. for the last few weeks, I''ve been reading Tricks of the Windows Game Programming Gurus and recently finished the chapters on GDI. All of these programs compile fine on my computer. However, when I tried to do some of my own work I would get an error whenever I tried to move the window or close it. When I do either I get a message box with "Object Windows Exception", "GDI Failure." I click OK and I then get several dozen page faults and Borland closes. For code, I''m basically using the base file from the end of Chapter 4. The error appears if all I do is create one brush and pen and try to draw a rectangle. Basically, I am wondering what this error is and if its my compiler or if this could happen on some other compiler, be it VC++ or some other one.
Advertisement
Maybe you can explain what the chapter is about so that people who don''t own the book can reply as well.
Are you checking the return values of the function calls that create the brush and pen? They may be failing and then you might be trying to use invalid values in later function calls.

Steve ''Sly'' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
The chapter deals with mainly drawing pixels, lines, polygons, ellipses, and rectangles using GDI from Windows.
Below are the main lines that I''m using to do the drawing, taken pretty much word for word from the book. I simply changed some of the values.

hdc = GetDC(hwnd);

red_pen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
black_brush = CreateSolidBrush(RGB(255, 255, 255));
SelectObject(hdc, red_pen);
SelectObject(hdc, black_brush);

Rectangle(hdc, 0, 0, 133, 133);

ReleaseDC(hwnd, hdc);
quote:Original post by Alusair
black_brush = CreateSolidBrush(RGB(255, 255, 255));
A minor point, but isn''t RGB(255, 255, 255) white, not black?
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]

This topic is closed to new replies.

Advertisement