The main purpose of this design is to prevent misuse of pens. If all the descriptors are just void * or int or long long or some other basic type, you have nothing to interfere with using one and not the other. The pointer to struct HWND__ and the pointer to struct HBITMAP__ are not the same thing, so if you have the following code:
HWND hwnd; HBITMAP hbmp; hbmp = GetBitmap(...); hwnd = hbmp;
This is a fairly classic method, ensuring that you get unique types so that the API provider does not want to provide a true ad. Although I'm not quite sure why they even need the right structure declaration, you could possibly get away with it:
#define DECLARE_HANDLE(n) struct n ## __; struct n ## __ *n;
It also ensures that any Dereferece HWND will not be possible, as the compiler will object to the "use of an incomplete type".
Mats petersson
source share