一、创建MFC 动态库工程

下一步

创建

点击确定
二、创建接口


这个是系统创建的,改成自己的接口。
头文件:
#ifndef __WEB_ENGINE__
#define __WEB_ENGINE__
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) bool __stdcall LoadUrl(const char* pUrl);
#ifdef __cplusplus
}
#endif
#endif
源文件:
#include "pch.h"
#include "WebView.h"
#include "ManageWebView.h"
__declspec(dllexport) bool __stdcall LoadUrl(const char* pUrl)
{
if (!pUrl) {
return false;
}
AFX_MANAGE_STATE(AfxGetStaticModuleState());
ManageWebView dlg;
dlg.DoModal();
return true;
}
截图:

三、mfc 动态库中创建界面
右击项目----》添加----》资源----》

选择对话框,点击新建

出现界面

四、给界面添加类,进行绑定
右击界面----》选择添加类


点击确定。
在资源试图中打开界面

右击对话框,选择类向导,添加事件
五、解决编译报错
添加resource.h,解决IDD_DIALOG1无法识别的问题
六、 说明
QT调用模态对话框属于资源类,需要在导出函数中开头增加
AFX_MANAGE_STATE(AfxGetStaticModuleState());
要不然会出现:

同时,该过程不支持WM_CREATE,同样的也不支持非模态调用,因为非模态调用会调用Create函数 pWidget->Create(IDD_DIALOG1, NULL),相当于非模态调用了WM_CREATE