静态库与动态库区别比较

库分为静态库和动态库

提供前者的供应者,提供出:头文件.h和静态链接(编译)库.lib。    这里的lib文件较大

提供后者的供应者,提供出:头文件.h 、导入库.lib、实际dll库.dll。   这里的lib文件较小


静态库的使用:

#include "..\lib.h"
#pragma comment(lib,"..\\debug\\libTest.lib")


动态库的使用,方法一:

#include "..\lib.h"
#pragma comment(lib,"..\\debug\\libTest.lib")
将动态库生成的*.dll文件放到EXE的同一目录下。

动态库的使用,方法二:
Another.dll有一个int Add(int x,int y) 函数。
typedef int (* FunPtr)(int,int); //定义函数指针
FunPtr funPtr;
Handle handle =LoadLibrary("Another.dll");
funPtr =(FunPtr)GetProcAddress(handle ,"Add");
funPtr(2,3); // 2+3;
FreeLibrary(handle); // 释放载入的动态库


 

猜你喜欢

转载自blog.csdn.net/changeholdon/article/details/48435691