首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

COPYDATASTRUCT的生存周期,该如何解决

2014-07-26 来源:读书人网 【读书人网(Reader8.cn):综合教育门户网站】
COPYDATASTRUCT的生存周期SendMessage(hWnd,WM_COPYDATA,NULL,(LPARAM)&cpd);我传递了内存过去,对方进程进

COPYDATASTRUCT的生存周期
SendMessage(hWnd,WM_COPYDATA,NULL,(LPARAM)&cpd);
我传递了内存过去,对方进程进行了修改,在sendmessage后想取得返回值。
WM_COPYDATA在sendmessage返回后还存在吗?
这种方式是否可行,是否可靠?

[解决办法]
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 lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer. 

[解决办法]
WM_COPYDATA 只能是单向的, 消息处理完会被释放
而且他实现的方式是内存映射, 数据是复制出来的, 两个进程用的不是同一块内存, 没办法回写
[解决办法]
不能msdn说的很清楚了
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.
[解决办法]
COPYDATASTRUCT在SendMessage时拷贝到共享内存区中,消息接收方从共享内存区中取得消息内容,与发送放已没有什么关系了
[解决办法]
试了一下,不同进程中,copydata的数据是单向的,同一进程中还是可以修改的。