I have created a DLL in C++ that contains a function which a program made in VB6 will use.
But i get the Overflow error when running the app.
I know for sure it is the function in the DLL that causes this.
Here is the function:
And it gets called from the VB6 app like this:Code:void __stdcall DLL_EXPORT CalculateGravity(double *X1,double *Y1,double *X2,double *Y2,double *FX1,double *FY1,double *FX2,double *FY2,double *W1,double *W2,double MaxAttraction,double MaxMovement,boolean AffectOnlyOne) { double dx; double dy; double d1; double d2; double F1; double F2; double TempX; double TempY; double D; if (AffectOnlyOne) //Only Particle 1 Moves { dx == *X1 - *X2; dy == *Y1 - *Y2; d1 == (dx * dx) + (dy * dy); if (d1 == 0) {d1 = 0.00001;} F1 == *W2 / (d1 * sqrt(d1)); if (F1 > MaxAttraction) {F1 == MaxAttraction;} TempX == *FX1 - (F1 * dx); TempY == *FY1 - (F1 * dy); D == sqrt((abs(TempX) * abs(TempX)) + (abs(TempY) * abs(TempY))); //When i remove this line of code here, the Overflow error stops occuring. if (D > MaxMovement) { D == D / MaxMovement; TempX == TempX / D; TempY == TempY / D; } *FX1 = TempX; *FY1 = TempY; } else //Both Particle 1 and Particle 2 Moves { //not done with this part yet } }
Basically what this function does is it calculates a bunch of stuff and then overwrites the result on two variables (FX1 and FY1). Those two variables is stored on the VB6 app that calls the function.Code:'Simulating the particles around the galaxy For i = 1 To UBound(P) - 1 CalculateGravity P(i).X(CurrentFrame), P(i).Y(CurrentFrame), P(0).X(CurrentFrame), P(0).Y(CurrentFrame), P(i).fx, P(i).fy, P(0).fx, P(0).fy, P(i).W, P(0).W, MaxAttraction, MaxMovement, True ReDim Preserve P(i).X(MaxProcessFrame + 1) ReDim Preserve P(i).Y(MaxProcessFrame + 1) P(i).X(CurrentFrame + 1) = P(i).X(CurrentFrame) + P(i).fx P(i).Y(CurrentFrame + 1) = P(i).Y(CurrentFrame) + P(i).fy Next
Also when i compile the DLL i get alot of warnings saying "Statement has no effect" on almost every line of code.
I'm new to C++, so excuse me if i'm missing something obvious here.
If anyone knows why i get those warnings and the Overflow error please let me know. Thanks.




Reply With Quote