0
votes

I have two applications that use one common DLL. From application "A' I have sent a message with string parameter as shown below

txt := 'Test String'
SendMessage(Handle, MyMessage, 0, lParam(PChar(txt)));

and in the same DLL I have another function to read that message, But I have received an empty message. I don't know where I am doing mistake.

procedure MyClass.WndMethod(var Msg: TMessage);
var
  Str: string;
begin
  case Msg.Msg of
    MyMessage:
    begin
      Str := string(PChar(Msg.LParam));
      ShowMessage(Str);  // Empty message
    end;
end;
1
Is it applicable to use WM_COPYDATA as described here stackoverflow.com/questions/10126342/…?SevenEleven
@SevenEleven I did that as well but i have received an empty message.Rahul Bajaj

1 Answers

1
votes

You are sending a private message between processes. The system does not marshal the data from one process to the other. That's needed because processes have private isolated virtual address spaces.

You are sending a pointer, an address to memory in the sending process. That address is received, but it is of no use because the receiving process cannot access the sending process memory. Hence the need to marshal the data between processes.

If you wish to marshal data between processes using messages, you should use the WM_COPYDATA message.