I have two applications, they communicate with messages, everything works as expected if I run two compiled exe. But when I start (debug) the sender from delphi ide (bds2006, tried with delphi 7 with no luck), sendmessage does not send anything.
It seems that the ideal prohibits sending messages to another application. I am using WM_COPYDATA, on win7 64bit and borland 2006.
any idea?
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.
Recipient 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;
source share