Reset DLL global variables

Posted on 2006-05-11
Last Modified: 2008-03-04
I'm linking some dlls explicitly and am curious... Is there any way to reset their global variables to what they were when you loaded the dll without reloading the dll? I'm curious because I want to keep everything loaded in memory and not have to unload and reload all the time...
Question by:Simoyd
    LVL 86

    Accepted Solution

    That depends on the way you initialize them. If you just use

    // globals
    int foo = 42;

    that indeed is only done when the module is loaded. You could however use a

    // globals
    int foo;

    void InitDllGlobals() {

    foo = 42;

    and call that from your 'DllMain()' like

    DllMain ( HINSTANCE hInst, DWORD dwReason, LPVOID) {

        switch ( dwReason) {
            // The DLL is loading due to process
            // initialization or a call to LoadLibrary.
            case DLL_PROCESS_ATTACH:




        return TRUE;


    or whenever you need to reset their values.
    LVL 2

    Assisted Solution

    If those are global variables , you can easily embed a timer in main which can call some function which reset all global variables   after stipulated time.

    even you can export that function and call it from your exe

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now