Soft Declare error. Failed condition : usage count

I am using soft declare to call a dll in windows. It works perfectly and i keep calling it based on some requirement. All of a sudden after some usage the app crashes with Runtime error. Saying failue condition : usage count. Does anyone can give any clue as what is this error. This dll works perfectly if used with c# language. This error happens at random time while calling the soft declare.

string reference counting may fail if you do something wrong…

If i do something wrong means it has to fail at the first attempt correct?

I have to call the DLL several times and it works every time and all of a sudden in one of the call the app crashes with Runtime error and this message “Failure condition : usage count”

If a variable is affected and it has e.g. reference count of 5 and it’s decremented by error, you would need 5 or 6 times till it fails.

This error is not happening at a particular interval. Its happening on a random count. Some after 50 calls. Another after 10 calls etc. At the same time same dll is perfectly working with c# and java programming.

It would be helpful if you post here, if possible, your Xojo code.

Declare Function GLY_AsyncAutoRepetitiveDeposit Lib “libglorycolx2010.dll” (ByVal h As Integer, p As Ptr, ByRef mRequestID As Integer) As Integer
Dim ret, mRequestID As Integer

ret = GLY_AsyncAutoRepetitiveDeposit(mHandle, Addressof CallBackDeposit, mRequestID)

Above is the code and called multiple times. It works perfectly and all of a sudden it crashes.

what are parameters of CallBackDeposit?

Its a method in module and i am getting the callback correctly. The parameter is a structure and i can see the values in structure as well.