title: Data transfer between different Delphi version apps via WM_COPYDATA
body: <p>I'm trying to make to Delphi applications communicate with each other via WM_COPYDATA. The problem I'm having though is is that the sender app is written in Delphi 7 and the receiver is written in Delphi 10.2 . I copied my Delphi 7 program's code into Delphi 10 and the communication worked perfectly. Using the exact same code in Delphi 7 however caused my string being passed to the receiver app to get corrupted. The codes I use are as follows:</p>
  
  <p>One the sending side I have:</p>
  
  <pre><code>procedure TSenderApp.SendString(ToSend: string);
  var
   copyDataStruct : TCopyDataStruct;
  
    receiverHandle : THandle;
     res : integer;
  begin
   copyDataStruct.dwData := 140500; //use it to identify the message contents
   copyDataStruct.cbData := (1+ Length(ToSend))* SizeOf(Char) ;
   copyDataStruct.lpData := pchar(ToSend) ;
  
   receiverHandle := FindWindow(PChar('TRecieverApp'),PChar('RecieverApp')) ;
     if receiverHandle = 0 then
     begin
       ShowMessage('CopyData Receiver NOT found!') ;
       Exit;
     end;
  
     res := SendMessage(receiverHandle, WM_COPYDATA, Integer(Handle), 
     LPARAM(@copyDataStruct)) ;
  end;
  </code></pre>
  
  <p>And on the receiving side I have:</p>
  
  <pre><code>procedure TRecieverApp.WMCopyData(var Message: TMessage);
  var
    p : PCopyDataStruct;
    l : Integer;
    s : string;
  begin
    p := PCopyDataStruct( Message.lParam );
  
    if (p &lt;&gt; nil) then
    begin
    ShowMessage('New Message Recieved!');
      l := p^.cbData;
      SetLength( s, (l+1) );
      StrLCopy( PChar(s), PChar(p^.lpData), l );
      Edit1.Text := s;
    end
    else
      Edit1.Text := 'ERROR';
  end;
  </code></pre>
  
  <p>What am I doing wrong? Or why is the message string being corrupted when sent from the Delphi 7 written SenderApp and not from the Delphi 10 written SenderApp?</p>