I
ifoundgoldbug
Ok here is a short description of what i am doing. I need to program
a dll for use by another program. the dll compiles fine but when i
call it from another program i get a stack corruption of the array in
the gamma section of the dll. so below i will post the code for in
order:
my dll header
my dll cpp
my testprogram header
my testprogram cpp
ANY help on this would be fantastic.
my dll header
#ifndef EICKEMEIER_INCLUDE
#define EICKEMEIER_INCLUDE
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a);
#endif
my dll cpp
#include <math.h>
#include <iostream>
#include <stdexcept>
using namespace std;
long double gammafcn( double x)
{
long double tmp, ser, stp, temp;
int j;
long double cof[6];
stp = 2.50662827465;
cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;
x = x - 1;
tmp = x + 5.5;
tmp = (x + 0.5) * log(tmp) - tmp;
ser = 1;
for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
}
temp =(exp(tmp + log(stp * ser)));
return temp;
}
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a)
{
double Rz, rx, fr, eick, temp;
long double gamma;
Rz = pow(zu * zo , 0.5) * (1 / tan(b * 3.14159265 / 180));
rx = pow((pow((x - xc) , 2) + pow((y - yc) , 2)), 0.5);
temp =2 / del;
gamma = gammafcn(temp);
fr = (sig * del) / (pow(2 * 3.14159265 , (1 - (2 / del))) *
pow(Rz , 2) * gamma) * exp(-3.14159265 * pow(sig , (del /
2)) * pow(rx / Rz , del));
eick = a * fr * volc;
return (eick);
}
my testprogram header
#pragma once
#include "resource.h"
my testprogram cpp
#include "eickDll.h"
#include "stdafx.h"
#include "testfile.h"
#include <iostream>
double Eickemeier();
using namespace std;
int main()
{
double x;
x = Eickemeier(0, 0, 0, 0, 2000000, 1, 2, 505, 5, 30, 1);
cout << x;
cin >> x;
return 0;
}
a dll for use by another program. the dll compiles fine but when i
call it from another program i get a stack corruption of the array in
the gamma section of the dll. so below i will post the code for in
order:
my dll header
my dll cpp
my testprogram header
my testprogram cpp
ANY help on this would be fantastic.
my dll header
#ifndef EICKEMEIER_INCLUDE
#define EICKEMEIER_INCLUDE
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a);
#endif
my dll cpp
#include <math.h>
#include <iostream>
#include <stdexcept>
using namespace std;
long double gammafcn( double x)
{
long double tmp, ser, stp, temp;
int j;
long double cof[6];
stp = 2.50662827465;
cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;
x = x - 1;
tmp = x + 5.5;
tmp = (x + 0.5) * log(tmp) - tmp;
ser = 1;
for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
}
temp =(exp(tmp + log(stp * ser)));
return temp;
}
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a)
{
double Rz, rx, fr, eick, temp;
long double gamma;
Rz = pow(zu * zo , 0.5) * (1 / tan(b * 3.14159265 / 180));
rx = pow((pow((x - xc) , 2) + pow((y - yc) , 2)), 0.5);
temp =2 / del;
gamma = gammafcn(temp);
fr = (sig * del) / (pow(2 * 3.14159265 , (1 - (2 / del))) *
pow(Rz , 2) * gamma) * exp(-3.14159265 * pow(sig , (del /
2)) * pow(rx / Rz , del));
eick = a * fr * volc;
return (eick);
}
my testprogram header
#pragma once
#include "resource.h"
my testprogram cpp
#include "eickDll.h"
#include "stdafx.h"
#include "testfile.h"
#include <iostream>
double Eickemeier();
using namespace std;
int main()
{
double x;
x = Eickemeier(0, 0, 0, 0, 2000000, 1, 2, 505, 5, 30, 1);
cout << x;
cin >> x;
return 0;
}