15,473
社区成员




#ifndef _GDLL_H_
#define _GDLL_H_
extern "C" int __declspec(dllexport) add(int x, int y);
#endif
#include "gdll.h"
int add(int x, int y)
{
return x+y;
}
#include "stdafx.h"
#include <windows.h>
typedef int(*lpAddFun)(int,int);
int main(int argc, char* argv[])
{
HINSTANCE hDll;
lpAddFun addFun;
hDll = LoadLibrary("./gDll.dll");//dll 名称就是这个,我已经把它拷贝到应用程序文件夹下了。
if (hDll != NULL)
{
addFun = (lpAddFun)GetProcAddress(hDll,"add");
if (addFun != NULL)
{
int result = add(2,4);//add为导出函数
printf("a+b= %d",result);
}
FreeLibrary(hDll);
}
return 0;
}