lesson19
来源:互联网 发布:定制婴儿知乎 编辑:程序博客网 时间:2024/05/17 06:03
1:动态库和静态库
静态库:函数和数据被编译进一个二进制文件(通常扩展名为.LIB)。在使用静态库的情况下,在编译链接可执行文件时,链接器从库中复制这些函数和数据并把它们和应用程序的其它模块组合起来创建最终的可执行文件(.EXE文件)。
在使用动态库的时候,往往提供两个文件:一个引入库和一个DLL。引入库包含被DLL导出的函数和变量的符号名,DLL包含实际的函数和数据。在编译链接可执行文件时,只需要链接引入库,DLL中的函数代码和数据并不复制到可执行文件中,在运行的时候,再去加载DLL,访问DLL中导出的函数。
2:动态链接库加载的两种方式
隐式链接
显示加载
3:拖动批处理文件.bat到命令窗口,就可以执行dumpbin命令了,但是只是当前窗口有效
他命令下有这些参数
查看一个动态库有哪些导出文件dumpbin -exprots dll1.dll
int _stdcall add(int a,int b)
{
return a+b;
}
int _stdcall subtract(int a,int b)
{
return a-b;
}
{
return a+b;
}
int _stdcall subtract(int a,int b)
{
return a-b;
}
加载引入库文件.lib后,在一下路径中查找该exe程序所需要的文件
查看程序需要加载那些动态库文件,有两种方式
①
②
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1:设计动态库
在动态库中函数前面加_declspec(dllexport),表示该函数是导出函数,调用该dll的程序可以调用该函数接口
_declspec(dllexport) int _stdcall add(int a,int b)
{
return a+b;
}
_declspec(dllexport) int _stdcall subtract(int a,int b)
{
return a-b;
}
_declspec(dllexport) int _stdcall add(int a,int b)
{
return a+b;
}
_declspec(dllexport) int _stdcall subtract(int a,int b)
{
return a-b;
}
2:让程序加载动态库
①加载lib文件
②寻找dll文件
没找到会出错
放在以上的路径中
3:在程序中调用导出函
在引用程序中加入这样的声明,这样能找到该函数的实现代码
说明这两个函数是外部定义的函数:
//extern int add(int a,int b);
//extern int subtract(int a,int b);
说明函数是从动态链接库的引入库中导入的,代码执行的效率会更高点
//_declspec(dllimport) int add(int a,int b);
//_declspec(dllimport) int subtract(int a,int b);
//extern int subtract(int a,int b);
说明函数是从动态链接库的引入库中导入的,代码执行的效率会更高点
//_declspec(dllimport) int add(int a,int b);
//_declspec(dllimport) int subtract(int a,int b);
void CDllTestDlg::OnBtnAdd()
{
// TODO: Add your control notification handler code here
CString str;
str.Format("5+3=%d",add(5,3));
MessageBox(str);
}
void CDllTestDlg::OnBtnSubtract()
{
// TODO: Add your control notification handler code here
CString str;
str.Format("5-3=%d",subtract(5,3));
MessageBox(str);
}
{
// TODO: Add your control notification handler code here
CString str;
str.Format("5+3=%d",add(5,3));
MessageBox(str);
}
void CDllTestDlg::OnBtnSubtract()
{
// TODO: Add your control notification handler code here
CString str;
str.Format("5-3=%d",subtract(5,3));
MessageBox(str);
}
0 0
- lesson19
- SQLi Labs Lesson19
- Lesson19 动态链接库DLL
- Windows程序设计__孙鑫C++Lesson19《动态链接库》
- Android开发视频教程-深入浅出系列Lesson19-AFF110727_蓝牙编程入门
- 孙鑫 Lesson19 动态链接库 显示与隐式
- C语言学习笔记 lesson19 文件处理函数
- 如何关闭CAD中的*BAK文件?
- Android 系统重启与关机:Java 代码实现(3)
- iOS开发一行代码系列:一行搞定输入框优化
- 4.查找最小的k 个元素
- Android WebView开发问题及优化汇总
- lesson19
- 人,说到底还是要靠自己。
- CAD中如何删除顽固图层?
- linux0.11init进程及shell原理分析
- OC内存管理剖析
- java只有值传递(P123)
- Windows终止线程的四种方法
- C语言之结构体
- coreText 的简单使用~