用WM_COPYDATA消息在进程间传送信息时遇到的问题(200分)

  • 主题发起人 brightangel
  • 开始时间
B

brightangel

Unregistered / Unconfirmed
GUEST, unregistred user!
想用WM_COPYDATA在我设计的两个程序间间传送信息,接收方始终捕获不到WM_COPYDATA消息
--------------------------------
发送程序码如下:
HWND WinHandle=FindWindow("TFormConfig","FTPScout 搜索引擎监控");
if(WinHandle!=NULL)
{
COPYDATASTRUCT cds;
char sTemp[1000];
strcpy(sTemp,Log.c_str());
cds.dwData=0;
cds.cbData=strlen(sTemp)+1;
cds.lpData=sTemp;
SendMessage(WinHandle,WM_COPYDATA,(WPARAM)this->Handle,(LPARAM)&cds);
}
--------------------------------
接收程序代码如下:
头文件中:
protected:
void __fastcall OnReLoadLog(TMessage &Message);
//指定消息的处理函数为
begin
_MESSAGE_MAP
MESSAGE_HANDLER(WM_COPYDATA, TMessage, OnReLoadLog)
END_MESSAGE_MAP(TForm);
CPP文件中:
void __fastcall TFormConfig::OnReLoadLog(TMessage &Message)
{
LoadLog();
}
--------------------------------
现在的问题是,接收方始终捕获不到WM_COPYDATA消息
对发送方单步调试证明可以找到接收方的窗口句柄
为什么?请各位高手指教!
不胜感激!
 
The WM_COPYDATA message is sent when an application passes data to another application.
WM_COPYDATA
wParam = (WPARAM) (HWND) hwnd;
// handle of sending window
lParam = (LPARAM) (PCOPYDATASTRUCT) pcds;
// pointer to structure with data

Parameters
hwnd
Identifies the window passing the data.
pcds
Points to a COPYDATASTRUCT structure that contains the data to be passed.
Return Values
If the receiving application processes this message, it should return TRUE;
otherwise, it should return FALSE.
Remarks
An application must use the SendMessage function to send this message,
not the PostMessage function.
The data being passed must not contain pointers or other references to objects
not accessible to the application receiving the data.
While this message is being sent, the referenced data must not be changed by
another thread of the sending process.
The receiving application should consider the data read-only. The pcds parameter
is valid only during the processing of the message. The receiving application
should not free the memory referenced by pcds. If the receiving application must
access the data after SendMessage returns, it must copy the data into a local buffer.
 
你的代码估计是有地方有问题啊,
 
还是不能解决问题啊!
 
很多书上都有这样的例子,找来对比一下就知道你那出了问题
 
好像是不能在BCB中运行
把BCB关掉,单独运行就可以了
 
呵呵,原因是你用FindWindows找到的窗口是IDE下的摸班窗口,当然发任何消息
都没有用啊,建议用内存映射文件来解决hWnd的问题
 
呵呵,同意
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
561
import
I
顶部