Announcement

Collapse
No announcement yet.

Global Values in DLL not cleared between calls

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global Values in DLL not cleared between calls

    I was caught by surprise. I am not sure if this is working as
    designed, but here is what I am seeing.

    I am not using multi-threads.

    I make a call to a DLL, the DLL call uses globals.
    (Its own globals)

    When I make a second call to the DLL the globals still have the
    values that were put their from the first call. Nothing was
    cleared.

    Is this normal and by design? For some reason I was thinking
    that the globals in a DLL are all reset at the beginning
    of each call, so I was surpised.

    Tim




    ------------------

  • #2
    Tim,

    Are you using this DLL in a Visual basic app - specifically are
    you starting and restarting from inside the VB design environment???

    I had a similar problem with my Cheetah DLL where the DLL does
    not unload between "restarts" and the values remained. I had to
    create a special function that essentially killed the DLL in
    memory by calling the Windows API function FreeLibrary.



    ------------------
    Paul Squires
    www.PlanetSquires.com
    mailto:[email protected]
    [email protected]
    </A>
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

    Comment


    • #3
      My program is all PBDLL.
      A Power Basic EXE is calling a Power Basic DLL.

      Tim


      ------------------

      Comment


      • #4

        Tim,

        If I understand you correctly, you are making two or more calls to the same DLL within your application. The global (and static) variables in the DLL will retain their values for the duration of the calling program, ie:

        1./ Call Foo1 in the dll, and set global 'g' (in the dll) to 1 from foo1
        2./ Call Foo2 in the dll, Foo2 displays a msgbox showing content of 'g', it will be 1.

        This is 'by design'

        ------------------
        Kev G Peel
        KGP Software, Bridgwater, UK.
        mailto:[email protected][email protected]</A>
        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

        Comment


        • #5
          Expected behavior: GLOBALs in DLLs maintain their value until changed or the DLL is unloaded.

          MCM

          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I had no idea it worked like that.

            Thanks guys!

            Tim


            ------------------

            Comment


            • #7
              Think of it this way: a GLOBAL works like a STATIC variable that is shared with _all_ subs/functions in a module.

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment

              Working...
              X