Using SetWindowLong is redundant here, and potentially dangerous. Presumably
what you're sending in lParam applies to one and only one message, so to use
SWL, your code would look like:
// Store a pointer to the data
SetWindowLong(hWnd, GWL_USERDATA, (LONG_PTR) &data);
// Tell the window about the data
SendMessage(hWnd, WM_USER, IDM_XXX, 0);
// Remove the pointer to the data
SetWindowLong(hWnd, GWL_USERDATA, 0);
Three problems with this code:
1) It uses an index in the window's data to store a pointer when there's a
perfectly good lParam parameter to SendMessage which could be used
2) It's not thread safe at all. If more than one thread was to try this
simultaneously, it's likely that the calls to SetWindowLong and SendMessage
would get jumbled up
3) If you later realised you needed to post the message, not send it, you'd
see problem (2) even in a single-threaded app
So I'd recommend carrying on using the lParam parameter to SendMessage to
pass a pointer, and forget about SetWindowLong for this.
--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/
Post by zliminatorI'm sending data to a modeless dialog using the WM_USER notification and
stuffing the data into the lParam for each different wParam message and then
unpacking the lParam it in the dialog. Is there a better way? I seem to
remember some example using Set/GetWindowWord/Long. Can someone give me a
hint? Thanks.
Dan