Calling Windows API routines from Fortran

In this section:

As the Windows API is based upon C++, it is easier to use the API from a C++ program. However, it is possible to program the API from Fortran but Fortran data structures do not easily map on to the data structures that are used by the Windows API. One way forward, is to employ mixed language programming, keeping your existing Fortran as far as possible unchanged, and using C++ to provide an interface to the Windows API.

Programmers who are not familiar with C++ will probably prefer to avoid learning a new language. If this is the case, the following points should be kept in mind when calling Windows API functions from Fortran.

All Windows API routines which do not take the address of a routine as an argument (or return one as a result) are available for calling from Fortran. Owing to the fact that the Windows API routines are written in C++, it is necessary to use the Silverfrost Fortran statement STDCALL to declare access to Win32 API routines. Examples of STDCALL statements can be seen in the file win32api.ins.

Each pointer argument to a Windows API routine has been specified as a WINREF or WINSTRING (the latter in the case of character arguments that need converting to null-terminated C-strings) and the actual argument should be a variable or array to which the pointer refers. The defintion of STDCALL appears below.



Copyright © 1999-2023 Silverfrost Limited