Lahey/Fujitsu Fortran  

Calling the Windows API

LF95 can directly access functions in the Windows API, with some limitations. You will need to have access to Windows API documentation and some knowledge of Windows Programming in C or C++ to take full advantage of this functionality, since the API is designed for C and C++.

Complete Windows applications can be written with Lahey Fortran 95 without resorting to using another language for the user interface. This might not be the best approach for many people, but examining how to do it can boost one's understanding of the issues, and these issues can crop up even when creating Windows applications using other approaches.

An example of this approach can be found in the Win32\Examples\Mix_Lang\WINAPI subdirectory, in the files WINDEMO.F90, WINDEMO.RC, WINDOWS.F90, and RUNWINDEMO.BAT

The first step is to compile the file WINDOWS.F90, found in the Win32\SRC subdirectory. Then USE the module WINDOWS_H in any procedure that will call the Windows API. WINDOWS.F90 is a Fortran translation of the standard windows header file WINDOWS.H, which contains definitions for various Windows parameters.

Next declare the API function with the DLL_IMPORT attribute in a type statement, for example, if you want to call the API function MessageBox:


Names with the DLL_IMPORT declaration are case sensitive. Elsewhere in your Fortran program the names of imported procedures are case insensitive.

Here are some more things to consider: