windows SendMessage 总是返回零?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2301371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SendMessage Always returns ZERO?
提问by nimo
Why does Windows SendMessage() always return ZERO, even the message delivery is success? Is there anyway to check the message delivery failure with SendMessage() ?
为什么Windows SendMessage() 总是返回零,即使消息传递成功?有没有办法用 SendMessage() 检查消息传递失败?
EDIT
编辑
Forgot to mention that I'm using SendMessage() inside a c++ DLL
忘了提及我在 C++ DLL 中使用 SendMessage()
LRESULT result = ::SendMessage(hwndOtherWindow,WM_COPYDATA, NULL/*(WPARAM)this->GetSafeHwnd()*/,(LPARAM)&structCDS);
"result" is always zero :(, but message delivers to other window successfully
“结果”始终为零:(,但消息成功传递到其他窗口
EDIT
编辑
BOOL CDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
return /*CDialog::OnCopyData(pWnd, pCopyDataStruct)*/ true; //true is the trick
}
采纳答案by Matthew Iselin
A zero return from SendMessage for WM_COPYDATAmeans the target application didn't process the message (FALSE = 0).
对于WM_COPYDATA从 SendMessage 返回零意味着目标应用程序没有处理消息 (FALSE = 0)。
The message might deliver successfully, but if the target application doesn't handle the message properly (ie, wrong return value, or passing it to the default window procedure) then your SendMessage call will appear to come back with the wrong result.
消息可能会成功传递,但如果目标应用程序没有正确处理消息(即错误的返回值,或将其传递给默认窗口过程),那么您的 SendMessage 调用似乎会返回错误的结果。
It might be worth your time to see what the target application's handling of the WM_COPYDATA message is, if possible.
如果可能,您可能需要花时间查看目标应用程序对 WM_COPYDATA 消息的处理方式。