进程间发送数据的问题

向其他进程的窗口发送数据,如果只是发送基本类型的数据,用不着使用WM_COPYDATA消息,因为Jeffrey Richter said in programming application for Microsoft windows: " Fortunately, most messages don't require this type of processing—it takes place only when an application sends interprocess messages. Special processing such as this has to be performed for any message whose wParam or lParam parameters represent a pointer to a data structure. " 我个人是这样理解的,WM_COPYDATA是个进程间消息通信,"It's a shame it's not used more frequently"(said by Jeffrey Richter),在wparam lparam是个结构的地址时如字符串等,WM_COPYDATA是使用的绝佳场合。若进程的消息通信,wparam,lparam只是些基本的数据类型的数据,是用不着WM_COPYDATA,因为他们不是地址,是与进程自身无关的数据,可以直接Send 或Post自己定义的消息。例如: CWnd * pWnd;  pWnd=CWnd::FindWindow(NULL,_T("Shell"));  if(pWnd!=NULL)  pWnd->PostMessage(WM_USER+120,(WPARAM)(int)nData,0);

使用WM_COPYDATA的注意事项:

 1.Always send this message; never post it. You can't post a WM_COPYDATA message because the system must free the memory-mapped file after the receiving window procedure has processed the message. If you post the message, the system doesn't know when the WM_COPYDATA message is processed, and therefore it can't free the copied block of memory.

 2.It takes some time for the system to make a copy of the data in the other process's address space. This means that you shouldn't have another thread that modifies the contents of the memory block running in the sending application until the call to SendMessage returns.

3.The WM_COPYDATA message allows a 16-bit application to communicate with a 32-bit application and vice versa. It also allows a 32-bit application to talk to a 64-bit application and vice versa. This is an incredibly easy way to have newer applications talk to older applications. Also note that WM_COPYDATA is fully supported on Windows 2000 and Windows 98.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值