MFC常规DLL的调用过程

4920阅读 0评论2013-01-15 dyli2000
分类:IT业界

1、单文档工程的创建:

image



image


 

2、找到工程的菜单编辑器中添加菜单项


image

 

 

3、为菜单添加事件处理函数


image


 

image


在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函数来装载。


image


5、案例运行效果:

image

 

6、案例代码上传

TestRegularDll.zip

上一篇:C#获取当前日期时间(转)
下一篇:软件设计单一原则SRP