This afternoon,although I have had a little out of my mind.I am so excited because I learned a lot MFC intellectal points from a bit topic. I have handled how to load a dll resource at an application Dialog box successfully.Before this,I checked it out for a long time, I read papers about Dll resource dialog box and how to call it dynamicaly.I can do this as following code to bring about purpose:
The Dll dialob box define like this:
By default,I think you have created a dll dll resource dialog box file,so here,I just only add portion of main code.
#include "myDllResource.h" //the dll resource dialog box header file.
CDllResourceApp theApp; //the global object of application procedure.
void __stdcall showDlg() // call dll dialog box function .
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
myDllResource dlg;
UINT iResult = dlg.DoModal();
}
showDlg function is an interface function and you must define it in the main application procedure. You also need to create *.def file as exported function (showDlg) template like this:
; DllResource.def : Declares the module parameters for the DLL.
LIBRARY "DllResource"
DESCRIPTION 'DllResource Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
showDlg
This file,you must define it at dll application file containing source files of DLL. Next,you should create a dialog box (exe) and add a button on the dialog Form to call dll resource dialog box.I know you a very smart to create this.the main part of code like this:
void CDemoDllDlg::OnCall()
{
// TODO: Add your control notification handler code here
typedef void (__stdcall *lpFun)(void); //function pointer
HINSTANCE hDll; //DLL handle(句柄)
CString dllPath;
CString resPath;
char fullPath[MAX_PATH];
ZeroMemory(fullPath,sizeof(fullPath));
::GetModuleFileName(AfxGetInstanceHandle(),fullPath,MAX_PATH);
resPath.Format(_T("%s"),fullPath);
resPath = resPath.Left(resPath.ReverseFind('//')+1);
dllPath = resPath + _T("DllResource.dll");
hDll = LoadLibrary(dllPath);
if (hDll == (HINSTANCE)HINSTANCE_ERROR)
{
MessageBox("Loading DLL failed!");
}
lpFun pShowDlg;
pShowDlg = (lpFun)GetProcAddress(hDll,"showDlg");
if (NULL==pShowDlg)
{
MessageBox("Searching DLL function failed!");
}
pShowDlg(); //call a dll resource dialog box by a function adddress.
}
I am so tired today~~!