I'm trying to write a security wrapper which checks 3 types of security. It make the security check call once only for each type. It stores the result of this check, and the fact that this check has been done, in 2 boolean variables.
So this is what is supposed to happen:
- for each license type (1,2,3) call the security function once only
- store the result of this call, and the fact that I have already called it, in 2 boolean variables
- then for every subsequent call, check if it has already been called; if it has just send back the saved result rather than calling security again
However I am getting some random issues. Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
static bool Techlib_Security_Checked[3] = {false, false, false};
static bool Techlib_Security_OK [3] = {false, false, false};
bool Check_Security_int (int type);
extern "C" _declspec(dllexport) bool Check_Security (int type)
{
bool result;
int ll = type-1;
result = false;
if(ll >= 0 && ll < 3) {
if(!Techlib_Security_Checked[ll]) {
Techlib_Security_Checked[ll] = true;
if(Check_Security_int(type)) Techlib_Security_OK[ll] = true;
}
result = Techlib_Security_OK[ll];
}
return (result);
}
bool Check_Security_int (int type)
{
bool result = true; // just a dummy here
return(result);
}
|
Questions:
1. Do the static arrays get initialized to false when the DLL is loaded?
2. Do their values persist across multiple calls to the function Check_Security?