I've got the same problem! I need to receive WM_COPYDATA in lazarus but it doesn't work. I wrote simple programs:
Sender:
-------------------
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows;
type
{ TForm1 }
TCopyDataStruct = packed record
dwData: DWORD; //up to 32 bits of data to be passed to the receiving application
cbData: DWORD; //the size, in bytes, of the data pointed to by the lpData member
lpData: Pointer; //Points to data to be passed to the receiving application. This member can be nil.
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
FReceiverFromWS : THandle;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
lCopyDataStruct: TCopyDataStruct;
Msg: String;
begin
FReceiverFromWS := FindWindow(NIL,PChar('receiver'));
if FReceiverFromWS = 0 then
begin
ShowMessage('CopyData receiver NOT found!');
Exit;
end;
Msg := 'bla bla';
lCopyDataStruct.dwData := 23432;
lCopyDataStruct.cbData := 1 + Length(Msg);
lCopyDataStruct.lpData := PChar(Msg);
SendMessage(FReceiverFromWS, WM_COPYDATA, wParam(0), lParam(@lCopyDataStruct));
end;
end.
-----------------------
Receiver:
-----------------------
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows;
type
{ TForm1 }
TWMCopyData = packed record
Msg: Cardinal;
From: HWND;//Handle of the Window that passed the data
CopyDataStruct: PCopyDataStruct; //data passed
Result: Longint;//Use it to send a value back to the "Sender"
end;
TForm1 = class(TForm)
Memo1: TMemo;
private
{ private declarations }
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.WMCopyData(var Msg: TWMCopyData);
begin
form1.Memo1.Lines.add('test');
end;
end.
-----------------------------------------
But this not working. I've tried version with wndproc but it not working too. Spy++ when I'm sending message shows:
<00001> 00420620 S WM_COPYDATA hwndFrom:(null) pcds:0213FD70
<00002> 00420620 R WM_COPYDATA fProcessed:False