I have two applications, they communicate with messages, everything works as expected if I run the two compiled exe. But when I run (debug) the sender from the delphi ide (bds2006, tried with delphi 7 without luck), the sendmessage doesn't send anything.
It seems like the ide prevent sending messages to the other application. I'm using WM_COPYDATA, on win7 64bit and borland 2006.
any idea?
The sender:
procedure TForm1.Button1Click(Sender: TObject);
var dst: THandle;
stringToSend : string;
copyDataStruct : TCopyDataStruct;
begin
stringToSend := 'Hello';
copyDataStruct.dwData := 0; //use it to identify the message contents
copyDataStruct.cbData := 1 + Length(stringToSend) ;
copyDataStruct.lpData := PChar(stringToSend) ;
SendData(copyDataStruct) ;
end;
procedure TForm1.SendData(const copyDataStruct: TCopyDataStruct) ;
var
receiverHandle : THandle;
res : integer;
begin
receiverHandle := findwindow( pchar('TForm2'), pchar('Form2') );
if receiverHandle = 0 then
begin
ShowMessage('CopyData Receiver NOT found!') ;
Exit;
end;
res := SendMessage(receiverHandle, WM_COPYDATA, Integer(Handle), Integer(@copyDataStruct)) ;
end;
end.
The Receiver part:
TForm2 = class(TForm)
private
procedure WMCopyData(var Msg: TWMCopyData ); message WM_COPYDATA;
public
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TReceiver }
procedure TForm2.WMCopyData( var Msg: TWMCopyData );
begin
ShowMessage( 'Received' );
end;