We have to use 3rd party DLL in our development process, unfortunately we can’t modify it or specify how library have to work.
Original library developers introduced state mechanic in their methods via static variables.
E.g.:
void foo()
{
static int a = 1;
if (a == 1)
{
/* some init logic */
a = 2;
}
}
Sometime we need bring the library to its original state.
Is there any way to reset static variables to their original values without any system “hacks”?
Our current solution is FreeLibrary/LoadLibrary, but we want to avoid it.
Your current solution is the cleanest solution.
The only alternative is to work out where the variable is stored in the DLL and modify it directly. But that’s a gross hack that is incredibly brittle. For example, if the 3rd party DLL changes then your hack may stop working with unpredictable effects.