Is it safe to change this c-cast to a reinterpret_cast?

It is safe, because WPARAM is defined as:

typedef UINT_PTR            WPARAM;

and _PTR suffix means the type is big enough to hold a pointer.

while HWND is:

 typedef HANDLE HWND;

where HANDLE is:

typedef void *HANDLE;

so size of void* and UINT_PTR are always the same. If you would store it in 64bit application and try read in 32 bit application, then you would get in trouble.

if you are still concenred if that is safe to do such casts, you can search Visual Studio sources (in C:\Program Files (x86)\Microsoft Visual Studio 8\ folder), and you will find lots of lines with reinterpret_cast<LPARAM>(...) and reinterpret_cast<WPARAM>(...).


Yes, this is fine, and is what reinterpret_cast is intended for, ie the "trust me I know what I'm doing" approach that C has to casting.