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.
- 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.
- 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.
- In the Project Settings dialog box (Fortran tab), make sure the type
of libraries specified is consistent with that specified for the Fortran DLL.
- If you need to specify linker options:
- In the visual development environment, specify linker options in the
Linker tab of the Project Settings dialog box.
- On the DF command line, place linker options after
the /link option.
- 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.
- Build the image that references the DLL.
When using the visual development environment:
- Make sure you have added the import library (created when you built the DLL file) to
the project by (click the FileView tab).
- Like building other projects in the visual development environment, use the Build
menu items to create the executable (see Defining Your Project).
When using the command line:
- Specify the import library at the end of the command line.
- If your DLL exports data that will be used by the application being built,
specify the same /alignment options that were used to build the DLL.
- If you are building a main application, omit the /dll option.
- When building a Fortran DLL that references another DLL, specify
the /dll option.
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