First, the package
1. File->projects->mfc dll-> input Regulardll;
2. Select "MFC Extension DLL"
3. Select the ResourceView view, and then regulardll the resource directory, right-click->insert-> dialog->new
4. New form Delete OK and cancel, create a new button, change the ID of the form to: Idd_dll_dialog, the button ID to: Idc_hello_button
5. Double-click the New button->ok create new class--class name named Cdlldialog-> double-click button, enter:
MessageBox ("Call database encapsulation here");
6.file->new->c++ Source File->global.cpp, which reads as follows:
#include "StdAfx.h"
#include "DllDialog.h"
extern "C" __declspec (dllexport) void Showdlg (void)
{
Cdlldialog Dlldialog;
Dlldialog.domodal ();
}
7. Add # include "Resource.h" in the StdAfx.h file
Second, call
Next build a project to call the DLL, the button to add the following code can be called.
void Cmfcregularcalldlg::onbutton1 ()
{
typedef void (*lpfun) (void);
HINSTANCE hDLL; DLL handle
hDLL = LoadLibrary ("D:\\cppprimerstudy\\dllstudy\\regulardll\\debug\\regulardll.dll"); There is a space to add the escape character, or to put Lib in the directory with relative path hDLL = LoadLibrary (_t (". \\LOGIN1\\RegularDll.dll "));
if (Null==hdll)
{
MessageBox (_t ("RegularDll.dll not Found"));
}
Lpfun Addfun; function pointers
Lpfun Pshowdlg = (lpfun) GetProcAddress (hDLL, "Showdlg");
if (NULL==PSHOWDLG)
{
MessageBox (_t ("Showdlg function not found in DLL"));
}
Pshowdlg ();
FreeLibrary (hDLL);
}
MFC DLL Encapsulation form detailed steps