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");
}
}
windows LoadLibrary使用示例
最新推荐文章于 2026-04-11 11:51:13 发布
本文提供了一个使用C++加载DLL并调用其函数以获取版本号的完整示例代码,包括如何加载DLL、设置当前目录、获取函数指针以及打印版本号。
5815

被折叠的 条评论
为什么被折叠?



