Question

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.

Était-ce utile?

La 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.

Autres conseils

Please consider reading the documentation. Remark section imposes the following rules:

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top