GDI+ and Graphics.GetHdc errors

D

decrypted

I am having a huge problem with using the GetHdc method of various graphics
objects in various user defined controls. I am constantly getting an
'invalid paramter used' error on my main thread in TOTALY RANDOM scenarios.
I have been trying to debug this for weeks...

Here is the scenario: 350+ clients running our application compiled in 1.1.
Using 2 third party control libraries (where the error is always occuring).
Various controls produce the problem in the simpelest of calls:
IntPtr hDC = doubleBufferGraphic.GetHdc();

m.WParam = hDC;

// Paint background first

PaintBackground(hDC);


// Call the ListView control to do its painting

base.WndProc(ref m);

The first line there is causing the error.

The error seems to be completely hidden inside of the GetHdc call. I have
never gotten the error on my machine. The error is HIGHLY random (almost
never the same window or control causes it) and in no way reproducable.
Error occures mostly on 98 machines, but we have reports on every single
machine (we do automatic error feedback with stack traces and screen shots).

I am thinking there is a problem with the video cards being used but I can't
find any documentation on the video card requirements for gdi+.

Has anyone else ever experienced anything like this at all or have ANY
insite into the problem?

Thanks

-dec
 
H

Herfried K. Wagner [MVP]

decrypted said:
I am having a huge problem with using the GetHdc method
of various graphics objects in various user defined controls.
I am constantly getting an 'invalid paramter used' error on
my main thread in TOTALY RANDOM scenarios.
I have been trying to debug this for weeks...

This error is thrown, for example, if you try to access a disposed
('Graphics') object. Does this error occut only with the 'GetHdc' method?
 
M

Mattias Sjögren

IntPtr hDC = doubleBufferGraphic.GetHdc();

Do you make sure that all HDCs retrieved by GetHdc() are released with
ReleaseHdc()? From your description it sounds like it could be a GDI
resource leak.



Mattias
 
D

decrypted

Yes they are released

Mattias Sjögren said:
Do you make sure that all HDCs retrieved by GetHdc() are released with
ReleaseHdc()? From your description it sounds like it could be a GDI
resource leak.



Mattias
 
D

decrypted

How do you know this? Where can I find info regarding this?!? I have been
thinking the same thing, it seems that a graphics object is being worked on
and then an error occures and the graphics object is disposed or
incomplete...or, the graphics object is being sent to Win32API to have some
work done and extrernaly a window closes or something that disposes of the
graphics object.

-dec
 
K

Kevin Westhead

decrypted said:
I am having a huge problem with using the GetHdc method of various graphics
objects in various user defined controls. I am constantly getting an
'invalid paramter used' error on my main thread in TOTALY RANDOM scenarios.
I have been trying to debug this for weeks...

[snip]

IntPtr hDC = doubleBufferGraphic.GetHdc();

m.WParam = hDC;

// Paint background first

PaintBackground(hDC);


// Call the ListView control to do its painting

base.WndProc(ref m);

The first line there is causing the error.

[snip]

Can you post a little more information about your paint handler? Have you
initiated a BeginPaint/EndPaint block? Have you set any ControlStyles?
 
D

decrypted

The general question is what is the red x and where does it come from? if
you have any resources/links whatever/wherever I need to research this
monster (too many code snippets to post)

thanks man
dec


Kevin Westhead said:
decrypted said:
I am having a huge problem with using the GetHdc method of various graphics
objects in various user defined controls. I am constantly getting an
'invalid paramter used' error on my main thread in TOTALY RANDOM scenarios.
I have been trying to debug this for weeks...

[snip]

IntPtr hDC = doubleBufferGraphic.GetHdc();

m.WParam = hDC;

// Paint background first

PaintBackground(hDC);


// Call the ListView control to do its painting

base.WndProc(ref m);

The first line there is causing the error.

[snip]

Can you post a little more information about your paint handler? Have you
initiated a BeginPaint/EndPaint block? Have you set any ControlStyles?
 
K

Kevin Westhead

decrypted said:
The general question is what is the red x and where does it come from? if
you have any resources/links whatever/wherever I need to research this
monster (too many code snippets to post)


The failure of GetHdc is most likely the result of errors accumulating
elsewhere, so it's difficult to offer any concrete advice without more
information. If you're passing a non-null WPARAM to the base control's
WNDPROC in response to WM_PAINT then the base control will not initiate a
BeginPaint/EndPaint block; you'll have to do this yourself before you draw
on the window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top