Hmmmmm..... I guessed that gadget handles were actually pointers so when I pass the pointer to c++ and check the value I get an int.... if the gadget handle is for a valid gadget I get some value. If the gadget is freed then I get 0. I know that there is still a chance that the memory maybe written over so this is not perfect. More over if I pass a value less then 9764864 the dll will causes a crash. I guess 9764864 is either not a valid or is a protected memory address. And Im sure this too may not be the same on every computer.....
C++
BBDECL bool BBCALL isGadget(int* ptr)
{
if (int(&ptr) < 9764864){ return false; }
// int x = *ptr; // will still crash comp if &ptr > 9764864... even in try block
try{
int x = *ptr;
if (*ptr == 0){return false;}
return true;
}
catch(...)
{
return false;
}
return false;
}
b+
win = createwindow(.....)
print isGadget(win) ; prints 1
freegadget win
print isGadget(win) ; prints 0
print isGadget(123) ; prints 0
So it works, NO CRASH. I just don't know how portable or reliable it is.
C++
BBDECL bool BBCALL isGadget(int* ptr)
{
if (int(&ptr) < 9764864){ return false; }
// int x = *ptr; // will still crash comp if &ptr > 9764864... even in try block
try{
int x = *ptr;
if (*ptr == 0){return false;}
return true;
}
catch(...)
{
return false;
}
return false;
}
b+
win = createwindow(.....)
print isGadget(win) ; prints 1
freegadget win
print isGadget(win) ; prints 0
print isGadget(123) ; prints 0
So it works, NO CRASH. I just don't know how portable or reliable it is.