I am using The GNU MP (MPIR) Library and i want to Use the provided mpf_class as an argument of an dynamically loaded function from a dll. My problem is, that in general the dll import and running of functions work, but as soon as I try to pass a mpf_class as function argument, i get a Runtime Expression saying : `
Exception thrown at 0x7BB6E491 in Fractal Explorer.exe: 0xC0000005: Access violation executing location 0x7BB6E491.
I am linking the GMP Library with both the executeable and the dll.
This is the code of the exe that fails:
#pragma once
#include <windows.h>
#include <mpirxx.h>
#include <iostream>
#include <utility>
#include <limits.h>
typedef long (__stdcall *f_lfunc)(mpf_class const_r, mpf_class const_c, unsigned long max_iter, unsigned long precision);
typedef int (__stdcall* f_ifunc)();
const wchar_t* GetWC(const char* c);
class DllFractal {
public:
DllFractal(const char *path) {
wchar_t* buf = (wchar_t *) GetWC(path);
hGetProcIDDLL = LoadLibrary(buf);
if (!hGetProcIDDLL) {
std::cout << "[DLL LOADER] Could not Load DLl : \"" << buf << "\"!" << std::endl;
unsigned int err = GetLastError();
std::cout << ": -------------------- errorcode: " << err << std::endl;
return;
}
get_iterations = (f_lfunc)GetProcAddress(hGetProcIDDLL, "get_iterations");
if (!get_iterations) {
std::cout << "[DLL LOADER] Could not locate the function \"get_iterations()\"" << std::endl;
unsigned int err = GetLastError();
std::cout << ": -------------------- errorcode: " << err << std::endl;
return;
}
}
virtual ~DllFractal() {
FreeLibrary(hGetProcIDDLL);
}
long getIterations(mpf_class r, mpf_class c, unsigned long max_iter, unsigned long precision) {
/*
This is where it fails!
*/
return get_iterations(r, c, max_iter, precision);
}
private:
f_lfunc get_iterations;
HINSTANCE hGetProcIDDLL;
};
const wchar_t* GetWC(const char* c)
{
size_t cSize = strlen(c) + 1;
size_t converted;
wchar_t* wc = new wchar_t[cSize];
mbstowcs_s(&converted, wc, cSize, c, cSize - 1);
return wc;
}
And this is the code of the function i'm trying to call in the dll :
unsigned long get_iterations(mpf_class const_r, mpf_class const_c, unsigned long max_iter, unsigned long precision) {
mpf_class two(2, precision);
mpf_class escape(4, precision);
mpf_class r(0, precision);
mpf_class c(0, precision);
mpf_class temp_r(0, precision);
unsigned long i;
for (i = 0; i < max_iter; i++) {
if (r * r + c * c > escape) {
break;
}
// f(z) = z^2 + c
temp_r = r;
r = temp_r * temp_r - c * c + const_r;
c = two * temp_r * c + const_c;
}
return i;
}
thanks in advance and if you need more information please tell me.
User contributions licensed under CC BY-SA 3.0