• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

Reset DLL global variables

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...
2 Solutions
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.
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now