Skip to main content
GameDev.net gamedev.net
🔒 Locked

WM_USER

Started by Zeblar Nagrim Dec 17, 2005 at 1:20 PM 14 replies 2.2k views
Original Post
Zeblar Nagrim
Zeblar Nagrim
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?
__filip
__filip
You can't pass pointers between different applications unless you use some kind of shared memory.
__filip
__filip
Can't you just pass it by value, or do you need more than 4 bytes?
Anon Mike
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
-Mike
Flimflam
Flimflam
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. :)
supercoder74
supercoder74
couldnt you use the volatile keyword in this occasion?
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.
mikeman
mikeman
Quote:
Original post by Flimflam
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. :)


You can pass the WM_USER message code through the COPYDATASTRUCT.dwData if you want.

Also, since it has been said in this thread and I've heard it numerous times: GlobalAlloc does not allocate shared memory accessible to multiple processes. The memory is still in the private address space of the process which called GlobalAlloc, and allocated from the heap(and in Win32, there is no difference between the local and the global heap). If you want to use shared memory, the easiest way would be to use File Mapping.
supercoder74
supercoder74
Quote:
Original post by Anonymous Poster
Quote:
Original post by supercoder74
couldnt you use the volatile keyword in this occasion?


No. There's nothing about this that would be helped by 'volatile'.


Ah, ok. I am confused about volatile. :P
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.
demonkoryu
demonkoryu
From MSDN:
Quote:

Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers.


In other words, use WM_APP instead of WM_USER.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.