利用wm_copydate消息进行进程间通信<br><br><br>发送端:<br><br>const<br> WM_MYMSG = WM_USER+10000;//用户判断是谁发的消息<br><br>procedure Tform_main.SendThisMessage;<br>var<br> msg : pchar;<br> DataBuffer: TCopyDataStruct;<br> <br>begin<br>msg:=pchar('hello world');<br><br>DataBuffer.dwData := WM_MYMSG;<br>DataBuffer.cbData := strlen(msg)+(1 * SizeOf(Char));<br>DataBuffer.lpData := msg;<br><br>//必须用 SendMessage<br>SendMessage( FindWindow(nil,'my window'),WM_COPYDATA,0,Longint(@DataBuffer))<br><br><br>end;<br><br><br>接收端:<br><br>procedure TMainForm.WMCopyData(var M: TMessage);<br>var<br> str : string;<br>begin<br> { Check wParam to ensure we know WHO sent us the WM_COPYDATA message }<br> if PCopyDataStruct(M.lParam)^.dwData = WM_MYMSG then<br> { When WM_COPYDATA message is received, the lParam points to}<br> Showmessage(PChar(PCopyDataStruct(M.lParam)^.lpData));<br> str := string(PChar(PCopyDataStruct(M.lParam)^.lpData));//如果需要为string,必须转换!!<br> Showmessage( str );<br>end;<br><br><br><br>