1、单文档工程的创建:
2、找到工程的菜单编辑器中添加菜单项
3、为菜单添加事件处理函数
在command函数中添加如下代码:
void CMainFrame::OnRegulardll()
{
char *name = "Kobe";
double wage = 5000;
HINSTANCE hDll; // DLL句柄
typedef void (* dllFunc)(char*,double); // 宏定义ShowWage函数
dllFunc theFunc; // 函数指针
/* LoadLibrary用来装载DLL */
hDll = LoadLibrary(_T("..\\RegularMFCDLL.dll"));
if(hDll != NULL)
{
theFunc = (dllFunc)GetProcAddress(hDll,"ShowWage");
}
else
{
AfxMessageBox(TEXT("load DLL fail!"));
return ;
}
theFunc(name,wage);//调用导出函数
FreeLibrary(hDll);
}
4、将RegularMFCDll.dll放到工程目录的根目录下,供LoadLibrary函数来装载。
5、案例运行效果:
6、案例代码上传







