(1)创建一个MFC的控展DLL工程,在资源中添加一个FormView窗口,并创建相应的类CDeviceManageView。添导出函数如下:
extern "C" AFX_EXT_API UINT Create(CRuntimeClass * * view,CWnd * p) { new CDynLinkLibrary(DeviceManageDLL); *view = RUNTIME_CLASS(CDeviceManageView); return(0); }
(2)调用DLL函数创建视图
HINSTANCE hDllInst = AfxLoadLibrary(CScale3DCGlobal::GetApplicationPath() + _T("\\DeviceManage.DLL")); if (hDllInst) { typedef UINT(*MYFUNC)(CRuntimeClass**,CWnd *parent); MYFUNC CreateViewUI = NULL; CreateViewUI = (MYFUNC)GetProcAddress(hDllInst, "Create"); if (CreateViewUI) { CRuntimeClass* pNewViewClass; CreateViewUI(&pNewViewClass,AfxGetMainWnd()); ASSERT(pNewViewClass); CCreateContext context; context.m_pNewViewClass = pNewViewClass; pChildFrame = new CScale3DCChildFrame; if (!pChildFrame->LoadFrame(32000,//与DLL中的资源ID一致 WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE, AfxGetMainWnd(), &context)) return; pChildFrame->SetWindowText(_T("通信连接")); pChildFrame->InitialUpdateFrame(NULL, TRUE); } //FreeLibrary(hDllInst); } }
原文地址:http://blog.51cto.com/9233403/2088697