1. MFC DLL
(1) Create a project, create an Arbitrary dialog box test program;
(2) Create an # include "ExpertFunc.h"
#pragma once
#include "MakeDLL.h"
There's a problem with this method.
CWnd * InitData (CWnd * pwnd/* Parent window pointer, passed in by the caller, typically the main dialog box */)
{
Afx_manage_state (AfxGetStaticModuleState ());
Makedll * Pdlg = new Makedll;
if (Pdlg->create (Makedll::idd, Cwnd::fromhandle (Pwnd->getsafehwnd ())))
{
Pdlg->setparent (PWND);
Pdlg->showwindow (Sw_show);
return PDLG;
}
return NULL;
}
extern "C" __declspec (dllexport) void Show ()
{
Afx_manage_state (AfxGetStaticModuleState ());
Makedll test;
Test. DoModal ();
}
(3) in. def
; Makemfcdll.def: Declares the module parameters of the DLL.
LIBRARY
Exports
; This can be an explicit export
InitData @1//No
Show @2
2. MFC application (1) Create an MFC application (2) Add a button in the window and double-click the build Event
Button event void Cdlltestdlg::onbnclickedbutton1 ()
{
TODO: Add control notification Handler code here
typedef void (WINAPI * testdll) ();
HINSTANCE Hmod;
Hmod =:: LoadLibrary (_t ("MakeMFCDLL.dll"));
if (Hmod = = NULL)
{
AfxMessageBox (_t ("Fail"));
}
Testdll Lpproc;
Lpproc = (testdll) GetProcAddress (Hmod, "Show");
cwnd* pWnd1 = Cwnd::fromhandle (m_hwnd);
if (lpproc! = (testdll) NULL)
(*lpproc) ();
FreeLibrary (HMOD);
/*hinstance Hmod;
Hmod =:: LoadLibrary (_t ("MakeMFCDLL.dll"));
LPARAM LPARAM = 0;
Load (_t ("MakeMFCDLL.dll"), _t (""), LParam); */
}
Code with the problem
void Cdlltestdlg::load (CString strmodulename, CString strtitle, LPARAM lparam/* = 0*/)
{
Determine if the number of tabs exceeds the set
/*cini INI;
if (M_wndtab.getitemcount () >= (int) ini. GetInt (_t ("System"), _t ("Maxtabs"), 10))
{
_startprompt;
if (startprompt) startprompt (Prompt_type_popup, _t ("Too many tabs, close some tabs before you try to open them. "), 0X0000FF, Prompt_pos_top_center, this, NULL, FALSE);
Return
}*/
cwnd* pWnd1 = Cwnd::fromhandle (m_hwnd);
hmodule hdll = LoadLibrary (strModuleName);
if (hdll)
{
typedef CWnd * (*intidata) (CWnd *);
Intidata InitData = (intidata) GetProcAddress (hDLL, "InitData");
if (InitData)
{
unsigned int uversion = 0;
CWnd * pWnd = InitData (PWND1);
if (pWnd)
{
Pwnd->showwindow (SW_SHOWNORMAL);
Pwnd->updatewindow ();
}
}
}
}
Reference: http://bbs.csdn.net/topics/390948839