tags:

views:

76

answers:

3

Or in my particular case a windows region (HRGN)?

Updated: The problems is the following:

I've a collection of objects, each of these objects can hold a HRGN. These region once acquired is released when the object is destroyed. Since some of those objects are stored in a std::vector I've to define an assignement operator.

Until now I've just assigned those HRGN, but that is a bug. If I duplicate such objects each one of those will try to delete the same region, and one of those wil be using a non existent region.

+3  A: 

No, it is not possible. GDI objects support only a single handle per object.

Fyodor Soikin
I hoped I was missing some api call, seem that the correction solution is to keep a reference counting myself. Thank you.
Ismael
+3  A: 

You cannot make a duplicate of HRGN handle, but you could get a copy using CombineRgn function.

Kirill V. Lyadvinsky
I though of that using RGN_COPY, but I didn't know how to create an empty region.
Ismael
Bad idea, GDI heap is very limited at least on older OSes.
Anton Tykhyy
Yes, you are right, I didn't consider that.
Ismael
It is limited ( [more about it](http://blogs.technet.com/markrussinovich/archive/2010/03/31/3322423.aspx) ) but the one region requires a very small amount of that memory.
Kirill V. Lyadvinsky
+1  A: 

Wrap each HRGN in a reference-counting object modeled after any smart pointer e.g. shared_ptr.

Anton Tykhyy