2015-04-02 72 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) 
}