只需要dll文件,不过def中也许有函数的名称。如果dll中有个函数 int Exp(int);
;
HINSTANCE hMod;
typedef int fnExp(int);
fnExp * fpExpPtr;
hMod = LoadLibrary("test");
char szMsg[40];
fpExpPtr = (fnExp *)GetProcAddress(hMod, "fnExport");
sprintf(szMsg, "%d", (*fpExpPtr)(200));
AfxMessageBox(szMsg);
FreeLibrary(hMod);
;
HINSTANCE hMod;
typedef int fnExp(int);
fnExp * fpExpPtr;
hMod = LoadLibrary("test");
char szMsg[40];
fpExpPtr = (fnExp *)GetProcAddress(hMod, "fnExport");
sprintf(szMsg, "%d", (*fpExpPtr)(200));
AfxMessageBox(szMsg);
FreeLibrary(hMod);
1、隐式加载
在“project settings"->"link"中将你的lib文件名(包含路径)填入,如果有多个lib,可以以空格分割。
然后在你的源码中直接使用就可以了。
extern int fn(int);
int a=fn(123);2、显式加载
直接在源码中使用以下代码
typedef int __stdcall FUN(int);
HINSTANCE hinstance;
hinstance=LoadLibrary("n:\xxx\a.dll")
FUN *fun=NULL;
fun=(FUN*)GetProcAddress(hinstance,"fn");
if(fun!=NULL);
int a=fn(123);
两种方法都要知道dll中输出函数的具体名称、形参、返回类型