Jump to content
  • Advertisement
Sign in to follow this  
Zeblar Nagrim

WM_USER

This topic is 4596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! Im trying to send over the value of a float variable from one application to another. The Win32 application who send the message:
float* g_pfTest = new float; <- global pointer

*g_pfTest = 22.4; <- just a test value
SendMessage(g_hwndOtherProgram, WM_USER+1, (WPARAM) 0, (LPARAM) g_pfTest ); 



In the Win32 applications Winproc that gets the message:
switch (message)
{
case WM_USER+1:
  float t = *(float*) lParam;
  char text[40];
  sprintf(text, "%0.3f", (float) t);
  MessageBox(hwnd, text, 0, 0);
  break;
}




The messagebox print "0.0", that isn't the correct value sent. Anyone know why?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You need to pass that by value.


SendMessage(g_hwndOtherProgram, WM_USER+1, (WPARAM) 0, (LPARAM) *g_pfTest );

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Or use the WM_COPYDATA message. Here is an example of sending a string to another window:

COPYDATASTRUCT cds;
cds.dwData = MyDataId; //Some unique number
cds.cbData = s_cast(strlen(str)+1);
cds.lpData = str;
SendMessage(window, WM_COPYDATA, 0, (LPARAM)&cds);

Share this post


Link to post
Share on other sites
You can still send the float directly without needing WM_COPYDATA. You just need to use a little care to prevent the compiler from converting it an integer and back again. Something like:

SendMessage(wnd, WM_USER+1, 0, * (LPARAM *) g_pfTest);
...
case WM_USER+1:
float t = * (float *) &lParam;

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
You can still send the float directly without needing WM_COPYDATA. You just need to use a little care to prevent the compiler from converting it an integer and back again. Something like:

SendMessage(wnd, WM_USER+1, 0, * (LPARAM *) g_pfTest);
...
case WM_USER+1:
float t = * (float *) &lParam;

This is the solution I would use. It allows you to still use WM_USER. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!