lovespring
lovespring

Reputation: 19559

How do I know it's a valid gdi region handle?

or other gdi handle, such as pen brush. how do i know is it valid?

Upvotes: 0

Views: 419

Answers (3)

Pierre
Pierre

Reputation: 4416

Try GetObject() or GetObjectType(). They should return NULL if the object handle is invalid.

I can see where you'd want to use this for debugging. In a perfect world, we keep track of our objects and know where they are at all times.

Ours is not a perfect world.

Upvotes: 0

valdo
valdo

Reputation: 12943

The answer is: where did you get the handle from?

Simply speaking, it's like with the art: how do you know it's authentic, not a fake? There're some "heuristics", but the only 100%-working way is to know where is it from.

So, regarding the GDI regions: you should only trust those region handles that are returned by GDI functions.

:)

Upvotes: 2

Hans Passant
Hans Passant

Reputation: 941455

You should never get yourself into a situation where you might be holding onto a handle that isn't valid. If necessary, set the handle to NULL after calling DeleteObject() so it is completely obvious. Assuming that a GDI function will give you a FALSE return value because you passed a bad handle isn't safe.

Upvotes: 5

Related Questions