Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi IDE prevent sending messages

Tags:

delphi

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;
like image 959
balazs Avatar asked Aug 03 '11 14:08

balazs


1 Answers

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.

like image 86
David Heffernan Avatar answered Nov 07 '22 14:11

David Heffernan