Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12469245
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: IT业界

2013-01-15 19:05:46

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

阅读(4796) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~