动态方式:
HINSTANCE hDllInst = LoadLibrary("youApp.DLL");
if(hDllInst)
{
typedef DWORD (WINAPI*MYFUNC)(DWORD,DWORD);
MYFUNCyouFuntionNameAlias=NULL;
// youFuntionNameAlias 函数别名
youFuntionNameAlias= (MYFUNC)GetProcAddress(hDllInst,"youFuntionName");
// youFuntionName 在DLL中声明的函数名
if(youFuntionNameAlias)
{
youFuntionNameAlias(param1,param2);
}
FreeLibrary(hDllInst);参考MFC调用dll
HINSTANCE hDllInst = LoadLibrary("youApp.DLL");
if(hDllInst)
{
typedef DWORD (WINAPI*MYFUNC)(DWORD,DWORD);
MYFUNCyouFuntionNameAlias=NULL;
// youFuntionNameAlias 函数别名
youFuntionNameAlias= (MYFUNC)GetProcAddress(hDllInst,"youFuntionName");
// youFuntionName 在DLL中声明的函数名
if(youFuntionNameAlias)
{
youFuntionNameAlias(param1,param2);
}
FreeLibrary(hDllInst);参考MFC调用dll
typedef unsigned int(_cdecl *MyaddFun)(unsigned int,unsigned int);
MyaddFun add_to;
handle = ::LoadLibrary("myDLL.dll");
if(handle == NULL)
{
MessageBox("动态链接库加载失败!");
return FALSE;
} add_to = (MyaddFun)GetProcAddress(handle,"add"); //add 你的封装的接口
在你需要使用的地方使用
int sum = add_to(nA,nB);
get = (MyaddFun)GetProcAddress(handle,"getit"); 我应该加载成功后这样声明函数是吗?
正解
get其实就是对应dll中getit方法的函数指针,调用的时候只需要 get.getit
现在的get与getit实际是同等的,只不过get是你外部定义调用,而getit是的你的dll库内部封装接口
SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO));
pGNSI = (PGNSI) GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")),
"GetNativeSystemInfo");
if(NULL != pGNSI)
{
pGNSI(&si);
}
else
{
GetSystemInfo(&si);
}