一、消息的注册
(1).定义消息
#define WM_CALLBACK WM_USER+1000
(2).消息的注册
BEGIN_MESSAGE_MAP
ON_MESSAGE(WM_CALLBACK, OnCallback)
END_MESSAGE_MAP()
(3).消息的实现
LRESULT OnCallback(WPARAM wParam, LPARAM lParam)
{
....
}
二、dll中存储对象指针和消息事件
HWND g_hCallbackWnd = null;
UINT g_uiCallbackMsgID;
//导出的回调接口
DWORD WINAPI callbackWnd(HWND hCallbackWnd, UNIT uiMsgID)
{
g_hCallbackWnd = hCallbackWnd;
g_uiCallbackMsgID = uiMsgID;
}
//在需要返回调用对象出使用
{
if (g_hCallbackWnd != null)
::PostMessage( g_hCallbackWnd ,g_uiCallbackMsgID , param1, param2); //需要立即执行使用SendMessage
}
三、对象调用dll(显示连接)
HMODULE m_hcdll;
m_hcdll = LoadLibrary(_T("***.dll"));
typedef DWORD(WINAPI *p_Callback)(HWND hCallbackWnd, UINT uiMsgID);
p_Callback m_pCallback;
//获取dll导出接口地址
m_pCallback = (p_Callback)GetProcAddress(m_hcdll, "callbackWnd");
//将对象与消息传入dll
m_pCallback (this->GetSafeHwnd(), WM_CALLBACK);