tags:

views:

503

answers:

3

According to MSDN

The return value specifies the result of the message processing; it depends on the message sent.

I know it is defined as

typedef LONG_PTR LRESULT;

Meaning it will be 8 bytes on 64bit machine but (!) ....

Does anyone know if it is safe to assume that only the lower 4 bytes are used and store it as an INT (for example).

Thanks in advanced,

RM

+4  A: 

No it's not safe, because the return value is defined by the message being sent and the handler.

If you control the handler and the message then it'd be possible, it's not safe in the general case.

James

James Ogden
+1  A: 

No it is not safe in general. Do not assume the downcast. Also, useful is to compile your code with /RTCc which ensures inadvertent casts are asserted at runtime.

Maverique
+1  A: 

Definitely not safe. If the message return is indeed a pointer, it is very well possible for the pointer to have its 33rd bit set - especially on machines with >4GB memory.

MSalters
This may also happen with less than 4GB, due to the memory virtualization.
efotinis