I have to write a reference counted wrapper class in C++11 for Win32 handles like HFONT, HWND, HMODULE and so on. I want to use a single WinHandle class that implicitly casts to all handle types (which are all a void* typedef). Unfortunately all handles have different functions to destroy the underlying object for example DestroyWindow(), CloseHandle(), DeleteObject() and so forth, thus i'd need a different class for every handle-type to implement the appropriate destroy-function. (that would be 47 classes + base class including user objects, gdi objects and kernel objects)
So is there a way to determine at runtime of which "type" the handle is or rather which function needs to be called? (In the documentation I only found the isWindow() function)
I already thought about using RTTI or calling all delete-functions until one of them succeeds. RTTI won't work because all HANDLE types are typedefs of void* and thus the same. The latter might work, but all handles must be unique for it to work properly (no GDI handle can ever have the same value as a user handle or kernel handle) otherwise it might cause bugs and memory leaks