DotNetter
DotNetter

Reputation: 426

Sending forward windows message

For example, I have just called GetMessage (or I am within CallWndMsg hook callback) and obtained lParam and wParam.

May to use SendMessage or PostMessage to resend this message to window of other process using just recieved lParam and wPAram without deep coping. I mean if these parameters (which often contains pointers for compunded structures) remain valid during this resending or I can face with a memory violation problem (or something similar)? If I can do it, how system decided when lPAram and wPAram could be released and deleted?

PS Seems I cann't do that for WM_COPYDATA, because msdn pointed that all passed data is alive only while message handler is working/ But what for other messages.

Upvotes: 0

Views: 335

Answers (1)

marcinj
marcinj

Reputation: 50036

You should not pass pointer from process A to process B, in process B such pointer (address) might point to freed memory or memory used by some other structures. WM_COPYDATA is one way to pass data between processes, you can actually pack each of you message into binary array, send it to other process using WM_COPYDATA, and in this second process unpack it and then send to itself unpacked message.

The only safe way to pass lParam and wPAram between processes is when they contain only DWORD data.

Upvotes: 2

Related Questions