Mega Code Archive

 
Categories / Delphi / System
 

How to comunicate process spanned with WM_COPYDATA

Title: How to comunicate process-spanned with WM_COPYDATA // Sender: Send data procedure TForm1.Button1Click(Sender: TObject); var aCopyData: TCopyDataStruct; hTargetWnd: HWND; begin with aCopyData do begin dwData := 0; cbData := StrLen(PChar(Edit1.Text)) + 1; lpData := PChar(Edit1.Text) end; // Search window by the window title hTargetWnd := FindWindowEx(0, 0, nil, PChar('WM_COPYDATA-Receiver')); if hTargetWnd 0 then SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@aCopyData)) else ShowMessage('No Recipient found!'); end; (* -------------------------------------------------------------------- *) // Recipient - Receive data type TForm1 = class(TForm) private { Private declarations } procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; public { Public declarations } end; procedure TForm1.WMCopyData(var Msg: TWMCopyData); var sText: array[0..99] of Char; begin // generate text from parameter StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData); // write received text label1.Caption := sText; end;