GetModuleHandle (NULL) Gets the current DLL module base address?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.