for example Process A(MFC Process),uses loadlibrary to load a dll and install a global hook(the hook procedure is in the dll).
I want this dll to pass any information to the Process A, So I used SendMessage in the hook procedure to send WM_COPYDATA to Process A,but it didnt work.The Process A(have setted onCopyData()) didnt receive the message , also the same as PostThreadMessage().
//Hook Procedure
__declspec(dllexport) LRESULT CALLBACK mousehook_proc(int nCode,WPARAM wParam,LPARAM lParam)
{
COPYDATASTRUCT cds;
MOUSEHOOKSTRUCT *pmhs = (MOUSEHOOKSTRUCT *)lParam;
int result = ::SendMessage((HWND)FindWindow(NULL,L"MySpyM"),WM_COPYDATA,(WPARAM)pmhs->hwnd,(LPARAM)&cds); return ::CallNextHookEx((HHOOK)hook_handle,nCode,wParam,lParam);
}
//The spy program porcess the WM_COPYDATA Message
BOOL CMySpyMDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
MessageBox(L"Get Message",L"Alert",NULL);
return CDialog::OnCopyData(pWnd, pCopyDataStruct);
}