Listing 13: ex5win.cpp, C++ file on Windows.
// ex5win.cpp Test file for calling Muller's method from an F77 dll
#include <iostream>
#include <windows.h>
#include <complex>
#include <cmath>
using namespace std;
complex<double> myFunc(complex<double> &x)
{
complex<double> temp;
temp = pow(x - complex<double>(1.0f, 0.0f),complex<double> (10.0f, 0.0f));
return temp;
}
int main()
{
HINSTANCE hDll = LoadLibrary("muller.dll");
typedef complex<double> (*pFunc) (complex<double>&);
typedef void (* LPFNDLLFUNC)(pFunc, double&,
int&, int&, int&, int&, complex<double>*,
int&, int*,int&);
LPFNDLLFUNC lpFunc = NULL;
lpFunc = (LPFNDLLFUNC)GetProcAddress(hDll, "muller_");
pFunc pf = (pFunc) &myFunc;
double eps = 1.0e-10;
int nsig, kn, nguess, n, itmax, ier;
nsig = 20;
kn=0;
nguess = 0;
n = 10;
itmax = 2000;
ier = 0;
int infer[10] = {0};
complex<double> *x;
x = new complex<double> [n];
int i;
for (i=0; i<n; i++)
{
x[i] = complex<double> (0.0f, 0.0f);
}
complex<double> temp;
lpFunc(pf, eps, nsig, kn, nguess, n, x, itmax, infer, ier);
for (i=0; i<n; i++)
{
std::cout << "x[" << i << "] = " << x[i]
<< ", iteration no. is "
<< infer[i] << std::endl;
}
delete [] x;
FreeLibrary(hDll);
return 0;
}