Building Executables that Use DLLs

When you build the executable that imports the procedures or data defined in the DLL, you must link using the import library, check certain project settings or command-line options, copy the import library so the Linker can locate it, and then build the executable.

To use the DLL from another image:

  1. Add the import .LIB file with its path and library name to the other image.

    In the visual development environment, add the .LIB import library file to your project. In the Project menu, click Add to project, then Files.

    On the command line, specify the .LIB file on the command line.

    The import .LIB file contains information that your program needs to work with the DLL.

  2. If your DLL exports data, consistently use the same project settings options in the Fortran Data category /alignment option as was used to create the DLL. In the Fortran Data compiler option category, specify the appropriate values for Common Element Alignment (common block data) and Structure Element Alignment (structures in a module). This sets the /alignment option, which specifies whether padding is needed to ensure that imported data items are naturally aligned.
  3. In the Project Settings dialog box (Fortran tab), make sure the type of libraries specified is consistent with that specified for the Fortran DLL.
  4. If you need to specify linker options:
  5. Copy the DLL into your path.

    For an application to access your DLL, it must be located in a directory on the search path or in the same directory as the main project. If you have more than one program accessing your DLL, you can keep it in a convenient directory identified in the environment path. If you have several DLLs, you can place them all in the same directory to avoid adding numerous directories to the path specification.

    When changing your path specification on a Windows Me, Windows 98, or Windows 95 system, you must restart the operating system for the change to take effect. On a Windows NT 4 or Windows 2000 system, you should log out and back in after modifying the system path.

  6. Build the image that references the DLL.

    When using the visual development environment:

    When using the command line:

    For example, to build the main application from the command line that references 4-byte items in a common block defined in dllfile.dll:

      DF /align:commons mainapp.f90 dllfile.lib