qt调动DLL

void func(void); // dll库中的函数
typedef void (*PFUNC)(void);

方法一:


HMODULE g_hAPIDLL = NULL;
wchar_t tcDLLPath[100] = L"D:\name.dll";
g_hAPIDLL = ::LoadLibrary(tcDLLPath);
if (NULL == g_hAPIDLL)
{
qDebug() << "load library failed";
return;
}
PFUNC pfunc = NULL;
pfunc = (PFUNC)GetProcAddress(g_hAPIDLL , "func");
if (pfunc == NULL)
{
qDebug() << "load g_ChangeStackerSetting failed";
return;
}

方法二:


QLibrary mylib("D:\name.dll");
mylib.load();
if(mylib.isLoaded())
{
qDebug() << "load library success";
PFUNC pfunc = NULL;
pfunc = (PFUNC)mylib.resolve("func");
if (pfunc)
qDebug() << "load func success";
}

注意:两种方式一般情况下都可行,特殊情况下只能用其中一种,可以都试试。

原文地址:https://www.cnblogs.com/onetaste/p/4890988.html