为何接收不到WM_COPYDATA消息?

附件中的Sample文件夹中的例子可以正常的接收到wm_copydata消息
但在另外的程序中用几乎同样的代码却不能成功。
想破脑袋也想不出为什么?



Sample中的例子完全参照http://support.做的
[ 本帖最后由 jiashie 于 2010-5-31 10:58 编辑 ]
#include <windows.h> #include <stdio.h> int main(int argc,char* argv[]) { COPYDATASTRUCT SendMsg; HWND TagWnd; char szTagWindowname[128] = {'\0'}; char szSendTxt[128] = {'\0'}; if(argc>2) { strcpy(szTagWindowname,argv[1]); } else { while(1) { flushall(); printf("请输入目标窗口的名字: \n"); scanf("%s",szTagWindowname); if(strlen(szTagWindowname)) break; } } TagWnd = FindWindow(NULL,szTagWindowname); if(!TagWnd) { printf("没有找到目标窗口,程序退出\n"); exit(0); } printf("请输入你要发送的字符串信息(小于128字节)\n"); scanf("%s",szSendTxt); SendMsg.dwData = 3353; SendMsg.cbData = strlen(szSendTxt); SendMsg.lpData = szSendTxt; if(SendMessage(TagWnd,WM_COPYDATA,0,(LPARAM)&SendMsg)) printf("消息发送成功\n"); else printf("消息发送失败\n"); getchar(); return 0; }目标:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; procedure FormShow(Sender: TObject); private { Private declarations } procedure OnMsg(var Msg: TMessage);message WM_COPYDATA; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } procedure TForm1.FormShow(Sender: TObject); begin Memo1.Clear; end; procedure TForm1.OnMsg(var Msg: TMessage); var pdata: PCopyDataStruct; EchoStr: ansiString; begin pdata:= PCopyDataStruct(Msg.LParam); if pdata.lpData <> nil then begin pbyte(pansichar(pdata.lpData) + pdata.cbData)^:= 0; EchoStr:= pansichar(pdata.lpData); Memo1.Lines.Add(EchoStr); end; Msg.Result:= 1; end; end.