Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetModuleHandle in a DLL

GetModuleHandle in a DLL

Scheduled Pinned Locked Moved C / C++ / MFC
c++comperformancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sawerr
    wrote on last edited by
    #1

    Hi "Then the loader maps the executable module at memory address 0x00400000 and the DLL module at 0x10000000." http://www.codeproject.com/KB/DLL/RebaseDll.aspx[^] I built a dll and export a function which is called GetModuleHandle(NULL); Then an MFC application which is included this dll. In Mfc app calling GetModuleHandle(NULL); returns 0x00400000. OK. But when i called an exported function in the dll, it returned 0x00400000 too. But I expected to see 0x10000000. So can we say GetModuleHandle(NULL) always returns EXE's load address even it is in a DLL?

    M 1 Reply Last reply
    0
    • S sawerr

      Hi "Then the loader maps the executable module at memory address 0x00400000 and the DLL module at 0x10000000." http://www.codeproject.com/KB/DLL/RebaseDll.aspx[^] I built a dll and export a function which is called GetModuleHandle(NULL); Then an MFC application which is included this dll. In Mfc app calling GetModuleHandle(NULL); returns 0x00400000. OK. But when i called an exported function in the dll, it returned 0x00400000 too. But I expected to see 0x10000000. So can we say GetModuleHandle(NULL) always returns EXE's load address even it is in a DLL?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      sawerr wrote:

      I built a dll and export a function which is called GetModuleHandle(NULL);

      GetModuleHandle is a Win32 API function. Did you export the same named function in a different namespace? From the GetModuleHandle() docs, lpModuleName parameter: "If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file)."

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        sawerr wrote:

        I built a dll and export a function which is called GetModuleHandle(NULL);

        GetModuleHandle is a Win32 API function. Did you export the same named function in a different namespace? From the GetModuleHandle() docs, lpModuleName parameter: "If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file)."

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S Offline
        S Offline
        sawerr
        wrote on last edited by
        #3

        No, I exported a function which is called GetModuleHandle(NULL); OK. I got answer. Thank you very much...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups