Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过函数的地址调用dll中的函数_C++_Dll - Fatal编程技术网

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

C++ 如何通过函数的地址调用dll中的函数,c++,dll,C++,Dll,我需要通过它的地址调用dll中的函数。可能吗 这是dll中的函数: HMODULE handle void sethandle(HMODULE a) { handle=a; } 应使用GetModuleHandle和GetProcAddress函数,代码如下: LPCWSTR lpszModule = L"kernel32.dll"; // here should be your dll file path name. HMODULE hModule = GetModuleHandleW(lp

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

这是dll中的函数:

HMODULE handle
void sethandle(HMODULE a)
{
handle=a;
}
应使用GetModuleHandle和GetProcAddress函数,代码如下:

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)
}

是否导出了该函数,看看GetProcAddress文档看看这里:你尝试了什么?你在哪里遇到麻烦的?答案是可以的,但我不知道是什么阻止了你。我有FARPROC地址,我认为可以通过指针来实现。