Calling conventions
The calling convention determines how a program makes a call and where the parameters are passed. In a single-language program, calling conventions are nearly always correct, because there is one default for all modules, and because the compiler and explicit interfaces enforce consistency between the caller and the called routine. In a mixed-language program, different languages cannot share the same interface declarations. It is easy, for example, to mistakenly link Fortran and C modules that use different calling conventions. The error would not become apparent until the bad call is made at run time, causing immediate program failure. Therefore, you should check calling conventions carefully for each mixed-language call.
Most Fortran compilers and Visual Basic share the same calling convention, usually referred to as STDCALL or PASCAL (this calling convention originated in Microsoft Pascal, and therefore its name). The STDCALL calling convention specifies that:
Parameters are pushed onto the stack in the order in which they appear in the function call.
The code that restores the stack is part of the called function (rather than the calling program).
This convention differs from that used in languages such as C. In C, parameters are pushed onto the stack in reverse order, and the calling program is responsible for restoring the stack.
Visual Basic does not have a way to change the calling convention, so you must use the appropriate options in your Fortran compiler to ensure that your Fortran subroutines adhere to the STDCALL convention (see below for a simple explanation of how to do this with your specific compiler)