动态链接库和静态链接库

Static Library
#include "lib.h"
#pragram comment(lib,"..\\debug\\libTest.lib")


Dynamic Library
1. 静态加载
需要提供 .lib .dll .h文件;
且在程序一开始运行的时候就要加载整个dll,否则程序不能运行;


#include "lib.h"
#pragram comment(lib,"..\\debug\\libTest.lib")
但是这种方法可以调用 Class method


2. 动态加载
只需要提供dll文件;
但是无法调用Class method


Handle h=LoadLibrary(dllName) 
GetProcAddress(h, functionName) //返回函数指针,通过指针调用function
FreeLibrary(h)


ex: Another.dll中有一个 int Add(int, int)函数。
typedef int(*FunPtr)(int,int);
FunPtr funPtr;
Handle h=LoadLibrary("Anthor.dll");
funPtr=(FunPtr)GetProcAddress(h,"Add");
funPtr(2,3);
FreeLibrary(h);
原文地址:https://www.cnblogs.com/bouygues/p/4479996.html