Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendMessage Always returns ZERO?

Tags:

c++

windows

Why does Windows SendMessage() always return ZERO, even the message delivery is success? Is there anyway to check the message delivery failure with SendMessage() ?

EDIT

Forgot to mention that I'm using SendMessage() inside a c++ DLL

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
 }
like image 601
nimo Avatar asked Feb 20 '10 06:02

nimo


1 Answers

A zero return from SendMessage for WM_COPYDATA means the target application didn't process the message (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.

It might be worth your time to see what the target application's handling of the WM_COPYDATA message is, if possible.

like image 160
Matthew Iselin Avatar answered Oct 27 '22 13:10

Matthew Iselin