Do a project want to get the module base address of this DLL in DLL internal code implementation, and do not know this DLL name
The simplest way is to think of GetModuleHandle (NULL), is it possible?
See if the answer to http://blog.csdn.net/guzhou_diaoke/article/details/8826558 is
Try it yourself:
DLL code (Testdll):
BOOL apientry DllMain (hmodule hmodule, DWORD ul_reason_for_call, lpvoid lpreserved ) { switch ( Ul_reason_for_call) {case Dll_process_attach: { hmodule hmodule = GetModuleHandle (NULL); WCHAR Wszhmodule[max_path] = {0}; swprintf_s (Wszhmodule, L "dll called GetModuleHandle (NULL) gets to the address: 0x%x", (DWORD) hmodule); MessageBoxW (0, Wszhmodule, L "hint", 0); } Case Dll_thread_attach: Case Dll_thread_detach: Case Dll_process_detach: Break ; } return TRUE;}
EXE code (TEST):
int _tmain (int argc, _tchar* argv[]) { LoadLibrary (L "Testdll"); return 0;}
The results obtained:
Conclusion:
Call GetModuleHandle (NULL) inside the DLL to get the main module (EXE) base Address
GetModuleHandle (NULL) Gets the current DLL module base address?