您的位置:首页 > 其它

windows LoadLibrary使用示例

2015-07-22 17:26 381 查看
typedef int(*HA_GetVersion_t)(); //定义函数指针类型

void TestLoadDll()
{
HINSTANCE hDll; //DLL句柄

TCHAR chCurDir[MAX_PATH] = {0};
GetCurrentDirectory(MAX_PATH, chCurDir);
SetCurrentDirectory(_T("E:\\libHasdk\\dll"));

hDll = LoadLibrary(_T("libHasdk.dll"));

SetCurrentDirectory(chCurDir);

if (hDll != NULL)
{

HA_GetVersion_t HA_GetVersion_p = NULL;

HA_GetVersion_p = (HA_GetVersion_t)GetProcAddress(hDll, "HA_GetVersion");

if (HA_GetVersion_p != NULL)
{
int version = HA_GetVersion_p();
printf("version = %d\n", version);
}
else
{
printf("the calling is error\n");
}

FreeLibrary(hDll);

}
else
{
printf("Load DLL Error or DLL not exist!\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: