How can I cast long to HWND (C++ visual studio 8)?
Long lWindowHandler;
HWND oHwnd = (HWND)lWindowHandler;
But I got the following warning:
warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size
Thanks.
HWND is a handle to a window. This type is declared in WinDef.h as follows:
typedef HANDLE HWND;
HANDLE is handle to an object. This type is declared in WinNT.h as follows:
typedef PVOID HANDLE;
Finally, PVOID is a pointer to any type. This type is declared in WinNT.h as follows:
typedef void *PVOID;
So, HWND is actually a pointer to void. You can cast a long to a HWND like this:
HWND h = (HWND)my_long_var;
but very careful of what information is stored in my_long_var. You have to make sure that you have a pointer in there.
Later edit: The warning suggest that you've got 64-bit portability checks turned on. If you're building a 32 bit application you can ignore them.