Listing 11: ex4win.cpp, C++ file on Windows.
// ex4win.cpp Test file for passing a function pointer // to an F77 function in a dll #include <iostream> #include <windows.h> float foo(float &x) { return x * 2.0f; } int main() { HINSTANCE hDll = LoadLibrary("ex4.dll"); typedef float (*pMyFunc)(float&); typedef float (* LPFNDLLFUNC)(pMyFunc, float&); LPFNDLLFUNC lpFunc = NULL; lpFunc = (LPFNDLLFUNC)GetProcAddress(hDll, "myeval_"); float x,y; pMyFunc pfunc = (pMyFunc) foo; x = 1.2f; y = lpFunc(pfunc, x); std::cout << "foo( " << x << " ) " << " = " << y << std::endl; FreeLibrary(hDll); return 0; }