2015-04-02 37 views
0

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

这是DLL函数:

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

您导出功能? [如果是这样](http://goffconcepts.com/techarticles/calldll.html),[否则](http://stackoverflow.com/questions/2918234/calling-a-non-exported-function-in-a- dll) – Axalo 2015-04-02 11:48:36

+1

看看'GetProcAddress'文档 – Predelnik 2015-04-02 11:48:54

+0

看看这里:[http://stackoverflow.com/questions/18100044/calling-win32-dl​​l-from-c](http://stackoverflow.com/questions/18100044/calling-win32-dl​​l-from-c) – 2015-04-02 11:49:47

回答

0

您应该使用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) 
} 
相关问题