Click here to Skip to main content
15,881,413 members

DLL pasts data to parent Process.

Revision 4
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
C++
__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);//The MySpyM Process("MySpyM" also the Window name) did not receive the WM_COPYDATA Message and if i replace the Message with WM_CLOSE,it received.......
			return ::CallNextHookEx((HHOOK)hook_handle,nCode,wParam,lParam);
	}


//The spy program porcess the WM_COPYDATA Message
C++
BOOL CMySpyMDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{

	MessageBox(L"Get Message",L"Alert",NULL);
		return CDialog::OnCopyData(pWnd, pCopyDataStruct);
}
Posted 6-Feb-13 1:37am by Keanu L.
Tags: ,