[Lazarus] SendMessage Bug Work Around.

Duncan Parsons D.Parsons at seamsltd.com
Fri Apr 23 17:37:05 CEST 2010


From: Michael Schnell [mailto:mschnell at lumino.de] 
Sent: 23 April 2010 14:39
>	AFAIR, WM_COPYDATA is the only message that can ONLY use
SendMessage,
>	since the pointer is only guaranteed valid during the
transaction (well,
>	initiator dependant, of course!)
>
>In Windows, it makes no sense to send messages like EM_LINEFROMCHAR
with PostMessage, as they are used to request a result from the 
>receiver that comes as the SendMessage function value, while
PostMessage does not have a function value other than true or false. 
>
>Do you suggest that the memory array the pointer defines and the
pointer itself automatically is managed to be valid for the receiver ? 
>
>-Michael

I can only speak from how I've used it.. Windows does 'something' with
WM_COPYDATA such that the memory is shared between both processes,
whether they be in the same application space or not.

I have used things like [NB away from a dev environment, so OTOH]
PCopyData = TCopyData;
TCopyData = record
  s: string;
end;

Sender:
PCD = new(PCopyData);
PCD^.s := 'Hello';
i := SendMessage(OtherApplicationFormHandle, WM_COPYDATA, PCD,0);
Label.caption := intotostr(i);


Receiver:
PCD := WParam;
Label.Caption := PCD^.s;
result := 5;


Note in http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx
where it says 'The sending thread is blocked until the receiving thread
processes the message. However, the sending thread will process incoming
nonqueued messages while waiting for its message to be processed.'

It's exciting stuff! I've found it very useful through the years.




More information about the Lazarus mailing list