Announcement

Collapse
No announcement yet.

Global Values in DLL not cleared between calls

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

  • Lance Edmonds
    replied
    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>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    I had no idea it worked like that.

    Thanks guys!

    Tim


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

    Leave a comment:


  • Michael Mattias
    replied
    Expected behavior: GLOBALs in DLLs maintain their value until changed or the DLL is unloaded.

    MCM

    Leave a comment:


  • Kev Peel
    replied

    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>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    My program is all PBDLL.
    A Power Basic EXE is calling a Power Basic DLL.

    Tim


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

    Leave a comment:


  • Paul Squires
    replied
    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>

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Global Values in DLL not cleared between calls

    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




    ------------------
Working...
X