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. How to get the current instance handle

How to get the current instance handle

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
7 Posts 3 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.
  • P Offline
    P Offline
    Per Nilsson
    wrote on last edited by
    #1

    I have searched for a way to get the instance handle of the module that my code is executing in. AfxGetInstanceHandle function available, but only when running as an MFC dll. GetModuleHadndle is available, but requires the path of the dllm which I don't have. I cannot inject code in DllMain to "remember" the instance handle because I don't have access to it. I have a solution that is quite extensive using "Process Helper", "PE Image Helper" APIs and are quite time consuming. I hope to find a better way of doing it. Probably there exist a way for it, but I haven't found it yet. Does anybody have a solution for it?

    D 1 Reply Last reply
    0
    • P Per Nilsson

      I have searched for a way to get the instance handle of the module that my code is executing in. AfxGetInstanceHandle function available, but only when running as an MFC dll. GetModuleHadndle is available, but requires the path of the dllm which I don't have. I cannot inject code in DllMain to "remember" the instance handle because I don't have access to it. I have a solution that is quite extensive using "Process Helper", "PE Image Helper" APIs and are quite time consuming. I hope to find a better way of doing it. Probably there exist a way for it, but I haven't found it yet. Does anybody have a solution for it?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Per Nilsson wrote: GetModuleHadndle is available, but requires the path of the dllm which I don't have. Actually you do. First make a call to GetModuleFileName(...).


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      P 1 Reply Last reply
      0
      • D David Crow

        Per Nilsson wrote: GetModuleHadndle is available, but requires the path of the dllm which I don't have. Actually you do. First make a call to GetModuleFileName(...).


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        P Offline
        P Offline
        Per Nilsson
        wrote on last edited by
        #3

        No This function returns the module name of the creating process, not the dll I am executing in. /Per

        B D 2 Replies Last reply
        0
        • P Per Nilsson

          No This function returns the module name of the creating process, not the dll I am executing in. /Per

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          If you only have to run on Windows XP or Windows 2003 then look at this one GetModuleHandleEx using the GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS flag.

          1 Reply Last reply
          0
          • P Per Nilsson

            No This function returns the module name of the creating process, not the dll I am executing in. /Per

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Are you sure? http://www.mvps.org/vcfaq/sdk/7.htm


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            P 1 Reply Last reply
            0
            • D David Crow

              Are you sure? http://www.mvps.org/vcfaq/sdk/7.htm


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              P Offline
              P Offline
              Per Nilsson
              wrote on last edited by
              #6

              Yes "The Win32 API GetModuleFileName() is what you need. If you pass NULL as the module handle parameter, the function returns the path of the module that created the process (in other words - the application's exe file)."

              D 1 Reply Last reply
              0
              • P Per Nilsson

                Yes "The Win32 API GetModuleFileName() is what you need. If you pass NULL as the module handle parameter, the function returns the path of the module that created the process (in other words - the application's exe file)."

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Did you not read the last sentence for some reason?


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                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