静态链接库:
#include "..lib.h"
#pragma comment(lib,"..\debug\libTest.lib") //指定与静态库一起连接
printf("2 + 3 = %d",add(2,3));
动态链接库:动态调用;静态调用
#include "windows.h"
typedef int ( * lpAddFun)(int,int);
int main(int argc, char* argv[])
{
HINSTANCE hDll; //DLL句柄
lpAddFun addFun; //函数指针
hDll = LoadLibrary("..\Debug\dllTest.dll");
if (hDll != NULL)
{
addFun = (lpAddFun)GetProcAddress(hDll,"add");
if(addFun!=NULL)
{
int result = addFun(2,3);
printf("%d",result);
}
FreeLibrary(hDll);
}
return 0;
}
静态调用
#include "windows.h"
#pragma comment(lib,"dllTest.lib")
//在link时,应链接dllTest.lib文件
//Lib库中仅仅是关于其对应DLL文件中函数的重定位信息