delphiinter-process-communicatwm-copydata

WM_COPYDATA: Can the receiver modify the COPYDATASTRUCT contents?


I am trying to communicate between two Windows applications in Delphi. Sender sends commands via SendMessage using WM_COPYDATA. That part is working fine. Is it possible for the receiver to reply back some result strings in the same call? It is failing for me and following is what is happening now.

  1. Sender uses WM_COPYDATA to send a command to the Receiver using the blocking call SendMessge.

  2. Receiver processes the command and modify the COPYDATASTRUCT with some result strings that must be sent back to the sender and exit out of the event handler

  3. Receiver's "SendMessage" function returns but the contents of the COPYDATASTRUCT are still unchanged.

Apparently Windows' messaging mechanism is not sharing the COPYDATASTRUCT memory between two applications. Instead it is making a copy.


Solution

  • WM_COPYDATA does just what it says: It copies the data from the source process to the target process. It does not copy the data back from the target process to the source process. If you want bidirectional communication, send another message the other direction.