سؤال

what are the windows messages privileges?

In the Application 1, I posted a message to Application 2:

PostMessage(handle, WM_LOCAL, 0, Integer(Lst));

In the Application 2, The Message Implementation:

var l: TStringList;
begin    
  ShowMessage('got 1');
  l := TStringList(Message.LParam);
  ShowMessage('got 2');
  Memo1.Clear;
  ShowMessage('got 3');

  if Memo1 = nil then
    ShowMessage('nil');

  //HERE : Access violation.
  //Memo1.Text := l.Text;
  //ShowMessage('got 4');

  Memo1.Lines.Add('good!');
  ShowMessage('got 5');

  l.Free;      
  ShowMessage('got 6');

  //Access violation Too..
  Memo1.Repaint;
  ShowMessage('got 7');

Why this happens?

Neither i can repaint the Memo, nor Access the Text property.

هل كانت مفيدة؟

المحلول

You can not share objects between applications. Even the pointer would point to the adressspace of the destination.
Maybe WM_COPYDATA will fit your requirements in copying data.

نصائح أخرى

It's not messages that have privileges, rather it is processes. The functionality is known as User Interface Privilege Isolation (UIPI). This functionality stops lower integrity level processes sending messages to higher integrity level processes.

But that's not your problem. Your problem is that each process has a separate address space. And so a pointer from one process means nothing in a different process. Which is why you encounter an access violation. The pointer that you receive points to memory in a different process and so is meaningless.

You need to use an inter-process communication (IPC) mechanism. For example, sending a WM_COPYDATA message, or named pipes, or sockets and so on.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top