WUYUANS
Just for Sharing

调用动态链接库dll

2011年12月29日 分类:学习笔记C++

接上一篇,完成dll创建后就可以调用他了。

先在函数外部声明。

typedef int (WINAPI  *FactorialFunc)(int);

然后在函数体内:

 FactorialFunc _factorialfunc;
 HINSTANCE hInstLibrary=LoadLibrary(_T("factorial.dll"));
 if (hInstLibrary==NULL)
 {
  FreeLibrary(hInstLibrary);
 }
 _factorialfunc=(FactorialFunc)GetProcAddress(hInstLibrary,"fact");
 if (_factorialfunc==NULL)
 {
  FreeLibrary(hInstLibrary);
 }

 CString s;
 int f;
 f=_factorialfunc(23);
 s.Format(L"%d",f);
 MessageBox(s);
 FreeLibrary(hInstLibrary);
作者:wuyuan 本文来自Wuyuan's Blog 转载请注明,谢谢! 文章地址: https://www.wuyuans.com/blog/detail/50