OS基础:动态链接库(二)

1.vc6.0新建工程MFC AppWizard[dll]工程 命名LptMfcDll1

2.在lptMfcDll1.h添加函数名声明

 

添加的代码:

 

1 //lptAddBegin
2 
3 void lptMfcTest1(void);
4 void lptMfcTest2(void);
5 
6 //lptAddEnd
View Code

3.在lptMfcDll1.cpp添加函数体的定义

 

添加的代码:

 1 //lptAddBegin
 2 void lptMfcTest1()
 3 {
 4     ::AfxMessageBox("MFC Dll 第一个测试函数! ");
 5 }
 6 
 7 void lptMfcTest2()
 8 {
 9     ::AfxMessageBox("MFC Dll 第二个测试函数! ");
10 }
11 
12 //lptAddEnd
View Code

4.在lptMfcDll1.defEXPORTS中添加

 

 

 

5.编译执行,动态库生成

 

下面是测试

1.新建测试工程MFC AppWizard[exe]工程 命名:LptMfcTest1

选择

其他全部按照默认

2.到了Dialog界面后新建两个button

3.右键点击设置button1的属性:

ID:IDC_lptMfcBtn1 (自己命名) 标题:测试第一个函数

button2同样设置

 

4.双击button添加函数

函数体内实现test1和test2函数的调用

5.在该cpp头文件处添加库的调用

其中#pragma comment(lib,"LptMfcDll1.lib")这一句的作作用就是把该库导入,也可以在工程设置处添加这个库实现相同功能

同样的 别忘了动态链接库(一)的做法,把lptMfcDll1.h、lptMfcDll1.dll、lptMfcDll1.lib复制在lptMfcTest1文件夹下。

 

6.编译执行 点击button1

可以看到,已经成功调用了lptMfcDll1.lib里的函数

原文地址:https://www.cnblogs.com/imLPT/p/3685947.html