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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Variable not same across process in DLL

Variable not same across process in DLL

Scheduled Pinned Locked Moved C / C++ / MFC
questionjsonperformance
3 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
    peterasloan
    wrote on last edited by
    #1

    I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.

    L L 2 Replies Last reply
    0
    • P peterasloan

      I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.

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

      It's difficult to visualise the actual sequence of events here, but it may be that on the second call into this dll it is getting reloaded somehow. Either that or there is another bug somewhere.

      1 Reply Last reply
      0
      • P peterasloan

        I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        You wont be able to access anything in other.dll declared in such a way from Run.dll because they will have different instance handles. The only thing preventing a big crash in try to do so will be MFC's safe pointers because it is an access violation to allow it. There are two ways around the problem provide a function that returns the status on a standard DLL interface function something like

        int OtherDLLStatus (void) {

        return (OtherDLLStaticVar);
        };

        Then publish it on the DLL interface and get the static variable status via that call. I think that is probably all you need. However Option 2 is use shared memory mapping http://msdn.microsoft.com/en-us/library/ms810613.aspx[^]

        In vino veritas

        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