tags:

views:

10

answers:

1

I have a parent dialog box and a child dialog box.when i post message from child to parent using PostMessageW(WM_SMESG,NULL,l_dvalue);where l_Value is double value but when i recieve this message in parent and then i am typcasting like double l_value = (double)lParam;then value in l_value always showing 0.0 but the value isend to parent was 0.5 what is the problem

A: 

Casting a double of value 0.5 to integer will be "rounded down"; the decimals are truncated to be more specific. The result of truncating .5 from 0.5 will always be 0. However, lParam is not big enough (32 bit) to hold a double value (64 bit). But, assuming float (32 bit) instead of double, you can do it as follows:

  • Bit-based "cast" from float to long: *((long*)(&myFloat))
  • Bit-based "cast" from long to float: *((float*)(&lParam))

Or the C++ way:

  • Bit-based "cast" from float to long: *reinterpret_cast<long*>(&myFloat)
  • Bit-based "cast" from long to float: *reinterpret_cast<float*>(&lParam)
Flinsch