Listing 5: ex2win.cpp, C++ file on Windows.

// ex2win.cpp  —  Test file for passing a single complex argument to 
// an F77 function in a dll, and getting the returned complex value
#include <complex>
#include <iostream>
#include <windows.h>
int main()
{
    HINSTANCE hDll = LoadLibrary("ex2.dll");
    typedef std::complex<float> (* LPFNDLLFUNC)
                         (std::complex<float>&);
    LPFNDLLFUNC lpFunc = NULL;
    lpFunc = (LPFNDLLFUNC)GetProcAddress(hDll, "foo_");
    std::complex<float> x, y;
    x = std::complex<float>(1.0, 2.0);
    y = lpFunc(x);
    std::cout << "y = foo(" << x << ") = " 
              << y << std::endl;
    FreeLibrary(hDll);
    return 0;
}