After much experimentation I have succeeded to call, from CVF, functions exported by Agilents GPIB instrument control DLL "agvisa.dll" which was clearly compiled from C.
The way to access a rountine in a DLL is cumbersome in any language, and uses a number of WINDOWS APIs that are
available by putting a "USE kernel32.dll" statement at the beginning.
First you have to load the target DLL as follows
P = LOADLIBRARY("agvisa32.dll"C) where P is an integer that will receive the starting address of the DLL
Then you have to get the address of a target function within the DLL and assign it to a FORTRAN function name by having the
following in your declarations (before executable statements)
POINTER(Q,VIOPEN) associates an address Q (yet to be found) to the FORTRAN function name VIOPEN
then
Q=GETPROCADDRESS(P, "viOpen"C) gets the address of the DLL function "viOpen" (C is case sensitive) into Q
which means you can now use the FORTRAN function name VIOPEN in a statement like
ISTATUS=VIOPEN(...argument list using C argument passing conventions......)
There must also be an INTERFACE statement to help fix the argument passing conventions and
specify that the C convention for cleaning up the stack upon return is used.
(see CVF HELP section on mixed language programming)
Now clearly I don't want to have all that garbage in every routine that then uses the function VIOPEN.
So I would like to do all that only once and for all in an INCLUDEd header to the main program.
The problem is then, how to make the function name (e.g. VIOPEN) visible in another subroutine.
If you do noting, it compiles, but throws out "unresolved symbol" at link time.
So I tried passing the name VIOPEN into the subroutine as an argument and declaring it EXTERNAL in the subroutine.
It compiled and linked, but didn't work.
Here is the solution however:
In the main program, where declarations like
POINTER(Q,VIOPEN) are contained,
add a NAMED COMMON area that will contain all pointer such as Q
e.g.
COMMON /POINTERS/Q,R,S,T etc
then in each subroutine that wants access to the DLL routines, include that common statement and a repeat of the declarations like POINTER(Q,VIOPEN) You will then find that you can use the function names e.g. VIOPEN in the subroutine.
This adds no execution time overhead to the subroutine, as these extra lines are merely declarations that are used at compile time only.