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 access application's extern variable inside a dll

How to access application's extern variable inside a dll

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
12 Posts 4 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.
  • R Offline
    R Offline
    rahul kulshreshtha
    wrote on last edited by
    #1

    I have an application which has several extern variables, I need to access them inside dll. Is that possible?

    CPalliniC L C 3 Replies Last reply
    0
    • R rahul kulshreshtha

      I have an application which has several extern variables, I need to access them inside dll. Is that possible?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      You may, for instance, pass them (their pointers or references) as parameters of a DLL function.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      R 1 Reply Last reply
      0
      • R rahul kulshreshtha

        I have an application which has several extern variables, I need to access them inside dll. Is that possible?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Use a shared header externing the variable in the dll. Include this in the exe, and then the linker will do the rest for you.

        ============================== Nothing to say.

        R 1 Reply Last reply
        0
        • CPalliniC CPallini

          You may, for instance, pass them (their pointers or references) as parameters of a DLL function.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          R Offline
          R Offline
          rahul kulshreshtha
          wrote on last edited by
          #4

          Thanks, I agree the way you are saying is right and genuine. But unfortunately I don't have exe's source code :) I have injected a dll into exe's process space and now want to get the data from exe's memory space. I tried with hooking the system level functions like LoadLibrary and TextOut etc but I could not hook GetProfileInt, CString's sprintf, format etc functions. Any way to do so ? I wonder who downvoted my question :D :D

          CPalliniC 1 Reply Last reply
          0
          • L Lost User

            Use a shared header externing the variable in the dll. Include this in the exe, and then the linker will do the rest for you.

            ============================== Nothing to say.

            R Offline
            R Offline
            rahul kulshreshtha
            wrote on last edited by
            #5

            Thanks Eric, But I don't have exe's code. See my above reply for more details.

            1 Reply Last reply
            0
            • R rahul kulshreshtha

              I have an application which has several extern variables, I need to access them inside dll. Is that possible?

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              you can access extern (and exported) variables in a DLL from an EXE. you cannot access variables in an EXE from a DLL. you could, in theory, decompile the EXE, find the references to the data you want, figure out if the data is statically or dynamically allocated, then create some mechanism to probe the EXE's memory at the right locations and times, etc.. a huge task.

              image processing toolkits | batch image processing

              R 1 Reply Last reply
              0
              • C Chris Losinger

                you can access extern (and exported) variables in a DLL from an EXE. you cannot access variables in an EXE from a DLL. you could, in theory, decompile the EXE, find the references to the data you want, figure out if the data is statically or dynamically allocated, then create some mechanism to probe the EXE's memory at the right locations and times, etc.. a huge task.

                image processing toolkits | batch image processing

                R Offline
                R Offline
                rahul kulshreshtha
                wrote on last edited by
                #7

                Thanks Chris for verifying that I cannot access variables in an EXE from a DLL directly. So I am doing the Huge task. Still I think hooking should work as it is working for few of the functions; I will try a little more before leaving hooks.

                L 1 Reply Last reply
                0
                • R rahul kulshreshtha

                  Thanks, I agree the way you are saying is right and genuine. But unfortunately I don't have exe's source code :) I have injected a dll into exe's process space and now want to get the data from exe's memory space. I tried with hooking the system level functions like LoadLibrary and TextOut etc but I could not hook GetProfileInt, CString's sprintf, format etc functions. Any way to do so ? I wonder who downvoted my question :D :D

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  So you're an hacker?! :-D I upvoted your question for balancing.

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  R 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    So you're an hacker?! :-D I upvoted your question for balancing.

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    R Offline
                    R Offline
                    rahul kulshreshtha
                    wrote on last edited by
                    #9

                    Nopes! I am not; but I like to explore the things at extreme level :-\

                    1 Reply Last reply
                    0
                    • R rahul kulshreshtha

                      Thanks Chris for verifying that I cannot access variables in an EXE from a DLL directly. So I am doing the Huge task. Still I think hooking should work as it is working for few of the functions; I will try a little more before leaving hooks.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      This is largely a waste of time as there is nothing in the executable file that would get you a reference to the location of the variables. The use of extern on a variable declaration merely tells the compiler that it exists in a different source module. Such references are then resolved by the linker but no more information about them is held in the EXE file.

                      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                      C 1 Reply Last reply
                      0
                      • L Lost User

                        This is largely a waste of time as there is nothing in the executable file that would get you a reference to the location of the variables. The use of extern on a variable declaration merely tells the compiler that it exists in a different source module. Such references are then resolved by the linker but no more information about them is held in the EXE file.

                        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                        C Offline
                        C Offline
                        Chris Losinger
                        wrote on last edited by
                        #11

                        that's true. i suppose i left out the "...in a debugger..." part.

                        image processing toolkits | batch image processing

                        L 1 Reply Last reply
                        0
                        • C Chris Losinger

                          that's true. i suppose i left out the "...in a debugger..." part.

                          image processing toolkits | batch image processing

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          What you wrote looked fine to me; I just think the OP read more into it than you intended.

                          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                          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