Delphi IDE prevent sending messages
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;
Here's a wild guess. You are running the application that receives the messages as administrator. In Vista and up, integrity level protection stops processes delivering messages to processes with higher integrity levels.
From the SendMessage
documentation:
Message sending is subject to UIPI (User Interface Privilege Isolation). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.
精彩评论