DLL里面如何进行消息映射?1、先.h中消息声明:afx_msg LONG OnComm(WPARAM ch, LPARAM port);
2、后.cpp消息映射:ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
3、最后.cpp中消息实现LONG CDLLBcvmApp::OnComm(WPARAM ch, LPARAM port)
{
return 0;
}
怎么才能实现上面的代码在DLL消息映射
2、后.cpp消息映射:ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
3、最后.cpp中消息实现LONG CDLLBcvmApp::OnComm(WPARAM ch, LPARAM port)
{
return 0;
}
怎么才能实现上面的代码在DLL消息映射
在实现文件中添加:
BEGIN_MESSAGE_MAP(YOUCLASSNAME, CCmdTarget)
ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
END_MESSAGE_MAP()
里面自带一个XXXXXApp消息声明添加了// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCOM_DLL_TESTApp)
afx_msg LRESULT OnComm(WPARAM ch, LPARAM port);
//}}AFX_VIRTUAL
//{{AFX_MSG(CCOM_DLL_TESTApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()我在里面的消息映射添加了BEGIN_MESSAGE_MAP(CCOM_DLL_TESTApp, CWinApp)
//{{AFX_MSG_MAP(CCOM_DLL_TESTApp)
ON_MESSAGE(WM_COMM_RXCHAR, OnComm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
然后添加一个LONG CCOM_DLL_TESTApp::OnComm(WPARAM ch, LPARAM port)
{
return 0;
}
可是没有用。。为什么
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCOM_DLL_TESTApp)
afx_msg LONG OnComm(WPARAM ch, LPARAM port);
//}}AFX_VIRTUAL
//{{AFX_MSG(CCOM_DLL_TESTApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
上面那个粘贴错了。
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}