Inconsistent results with c++ dll
I have been given a C++.net dll that I must call from within excel vba. The call is made to a function of type integer (i.e., long in vba). VBA calls the function ~100 times every time the code is run. I start excel and run the code and the function returns the correct answer (I have a test data set that yields a known result). I can rerun the code as many times as I want in quick succession and the function still returns the correct answer. The problem occurs if I run the code, wait for several minutes, then rerun it. At that point, the function suddenly returns a different (and incorrect) result. Once the function returns the incorrect answer, it keeps returning the same incorrect answer every time the code is run regardless of the number of times run or the time between runs.
Any ideas? Because the function initially returns the correct results I suspect the problem lies in the dll. I'm a novice to c++ and the dll code is quite complex, but I've done my best to check for common memory leaks, etc. and haven't found anything. Any idea why the function returns the correct result unless I wait several minutes then rerun it - what is happening during that time to suddenly alters things? Thanks in advance for any help you can give.

