I have a DLL that I need to call. It's written in Pascal and although I have the source, I don't have pascal so I'm stuck with using the compiled DLL. The problem I have is that when I call a function, it seems to be using the pointer and then changing MY memory - and not just the variable I passed it, other variables nearby. So when I am in the middle of doing something else (normally writing debug), my data is changing.
My question is, is there any way to prevent the DLL from doing this? I tried adding a buffer zone between the memory I pass it and the memory I use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void MyClass::myFunction(int myParameter)
{
int myVariable;
int myOtherVariable = myParameter * 2;
int ignore[10000];
ignore[0] = 0; //Just to stop compiler warning about unused variable!
int variableToPass = 40;
int otherVariableToPass;
for (myVariable = 0; myVariable < myOtherVariable; myVariable++)
{
otherVariableToPass = 0 + myVariable;
CallNaughtyDLL(variableToPass, otherVariableToPass);
qDebug("Print some nice debug %d", myVariable);
}
}
However this just results in a Segmentation Fault at the end of the function on the line with the last }. I guess because the naughty DLL is still using the memory?
It would help quite a bit more if we could see the exact code in question, and possibly the Pascal code for the DLL or a link to where we can get it online.
How odd. I'm in the UK and have no problem on that page. I have however found a forum where they talk about products made by velleman and doing a search revealed a new version of the DLL which although still has the problem, also gives another method. Using this new method, I can just use all my data to build an array and send it all at once, so the call is no longer inside a loop. This seems to mean that segmentation fault crashes don't happen (though more by luck than judgement I think).
What I'm saying I guess is that I've resolved my problem for now but I'd still like to know (and might be useful to others) if / how you can get around a buggy DLL crashing your program.