title: How do I send floats in window messages
body: <p>What is the best way to send a float in a windows message using c++ casting operators?</p>
  
  <p>The reason I ask is that the approach which first occurred to me did not work. For the record I'm using the standard win32 function to send messages:</p>
  
  <pre>
  PostWindowMessage(UINT nMsg, WPARAM wParam, LPARAM lParam)
  </pre>
  
  <p>What does not work:</p>
  
  <ul>
  <li>
  Using <code>static_cast&lt;WPARAM&gt;()</code> does not work since <code>WPARAM</code> is typedef'ed to <code>UINT_PTR</code> and will do a numeric conversion from float to int, effectively truncating the value of the float.
  </li><li>
  Using <code>reinterpret_cast&lt;WPARAM&gt;()</code> does not work since it is meant for use with pointers and fails with a compilation error.
  </li></ul>
  
  <p>I can think of two workarounds at the moment:</p>
  
  <ul><li>
  Using <code>reinterpret_cast</code> in conjunction with the address of operator:
  <pre>
  float f = 42.0f;
  ::PostWindowMessage(WM_SOME_MESSAGE, *reinterpret_cast&lt;WPARAM*&gt;(&f), 0);
  </pre>
  </li><li>
  Using an union:
  <pre>
  union { WPARAM wParam, float f };
  f = 42.0f;
  ::PostWindowMessage(WM_SOME_MESSAGE, wParam, 0);
  </pre>
  </li></ul>
  
  <p>Which of these are preffered? Are there any other more elegant way of accomplishing this?</p>