On Feb 28, 2010, at 5:37 PM, Jon Cruz wrote:
Oh, and the root cause here is that NO casts to unsigned long should have been used. In Win64 you have the situation where Microsoft went with LLP64 instead of LP64 so that LONG is the same as INT (both stay 32-bit), while pointers such as HINSTANCE go to 64 bit.
So the main problem here is that the cast to unsigned long may have worked on win32, but on win64 that will truncate the pointer, loosing the top half of it's value. This gives the situation where the compiler does not warn, but then at runtime random failures can occur.
So instead of downcasting that HINSTANCE (aka pointer) to a smaller int, the int constant (32 in this case) needs to be upcast to the HINSTANCE type. Or a large enough int type could be used... but that is a bit trickier to get right.
But to summarize, for 64-bit code it is very important to look closely to each and every cast, and to be aware of the different models that might be in play.