如何通过dll中的地址调用函数

How to call function in dll through its address

本文关键字:地址 调用 函数 何通过 dll      更新时间:2023-10-16

我需要通过dll中的函数地址调用它。有可能吗?

这是dll中的函数:

HMODULE handle
void sethandle(HMODULE a)
{
handle=a;
}

您应该使用GetModuleHandleGetProcAddress函数,以下代码:

LPCWSTR lpszModule = L"kernel32.dll"; // here should be your dll file path name.
HMODULE hModule = GetModuleHandleW(lpszModule);
if (hModule)
{
    typedef void(*fn)(HMODULE);
    fn pF = (fn)GetProcAddress(hModule, "sethandle");
    // use it, like this: pF(a)
}