WM_COPYDATA: Can the recipient change the contents of the COPYDATASTRUCT?

I am trying to establish communication between two Windows applications in Delphi. The sender sends commands via SendMessage using WM_COPYDATA. This part works fine. Is it possible for the receiver to answer multiple lines of result in a single call? This is unfortunate for me, and this is what is happening now.

  • The sender uses WM_COPYDATA to send a command to the receiver using a blocking SendMessge call.

  • The receiver processes the command and modifies COPYDATASTRUCT with some result lines to be sent back to the sender and exit the event handler

  • The SendMessage function returns the recipient, but the contents of the COPYDATASTRUCT remain unchanged.

Obviously, the Windows messaging engine does not transfer COPYDATASTRUCT memory between the two applications. Instead, he makes a copy.


source to share

2 answers


does only what it says: it copies data from the source process to the target process. It does not copy data from the target process to the source process. If you want bi-directional communication, send another message in a different direction.



Read the documentation. The Remark section imposes the following rules:

The receiving application must consider read-only data. The lParam is only valid during message processing. The receiving application must not free memory referenced by LPARAM. If the receiving application needs to access the data after the SendMessage returns, it must copy the data to a local buffer.



All Articles