How to Create a FORTRAN DLL and Call It from Visual BasicLast reviewed: June 21, 1995Article ID: Q123841 |
The information in this article applies to:
SUMMARYThis article shows you how you can create a FORTRAN Dynamic Link Library (DLL) for Microsoft Windows and call the procedures it contains from Microsoft Visual Basic for Windows. You must have Microsoft FORTRAN Optimizing Compiler version 5.1 (or later) for MS-DOS and OS/2 to create a FORTRAN DLL.
MORE INFORMATIONThere are several steps to linking DLLs written in FORTRAN to Visual Basic programs. These steps are briefly described below and explained in detail later in this article. First, create or modify the FORTRAN procedures. You can use Programmer's Workbench to create or modify FORTRAN procedures. You can use SUBROUTINE and FUNCTION procedures. The procedures must follow these rules:
Now you're ready to compile the source code to produce an object file, and then link it to actually create the DLL. Note that Visual Basic expects all DLL procedures to take far pointers to values passed by reference. Windows also imposes some restrictions on DLLs. You can use compiler switches to create a DLL-ready object file, but you will need to have the appropriate static-link (.LIB) library to create the DLL. Next, write the Visual Basic procedure declarations for each procedure. These will tell Visual Basic several things:
Step-by-Step Example
Additional NotesDLL procedure and library names are not case sensitive to Visual Basic. Also, the Declare statements can be in any module in your project. If they are in a .BAS file, then they will be global to your project. If they are in a .FRM file, the DLL functions can only be called from within that form. You may get a general protection (GP) fault when you call a procedure in your DLL. The most likely cause is that your Declare does not exactly match the FORTRAN procedure. Check these areas:
Compatible Data Types in FORTRAN and Visual BasicThe following table shows conversion information between some FORTRAN data types and Visual Basic data types:
FORTRAN data types Visual Basic data types
INTEGER*2 Integer INTEGER*4 Long REAL Single REAL*4 Single DOUBLE PRECISION Double REAL*8 Double LOGICAL*2 Integer LOGICAL*4 Long CHARACTER*n String*n (Passed ByVal)For more information on calling DLLs, please see Chapter 24, "Calling Procedures in DLLs" of the Programmer's Guide for Microsoft Visual Basic version 3.0 for Windows.
|
Additional reference words: 1.00 2.00 3.00 5.10 GPF
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |