Chapter 3 Windows 95/NT Compiler/Linker Issues
©
National Instruments Corporation 3-21 LabWindows/CVI Programmer Reference Manual
To customize an import library, you must have an include file that contains the declarations
of all the functions you want to export from the DLL. Load the include file into a Source
window, and execute the Generate DLL Import Source command in the Options menu.
After you have generated the import source, you can modify it, including making calls to
functions in other source files. Create a new project that contains the import source file and
any other files it refers to. Select Static Library from the submenu attached to the Target
command in the Build menu of the Project window. Execute the Create Static Library
command.
Note This import source code does not operate in the same way as a normal DLL import
library. When you link a normal DLL import library into an executable, the
operating system attempts to load the DLL as soon as the program starts. The
import source code LabWindows/CVI generates does not load the DLL until you
call one of the functions it exports.
Preparing Source Code for Use in a DLL
When you create a DLL, you must address the following issues that can affect your source
code and include file:
• The calling convention you use to declare the functions you want to export
• How you specify which DLL functions and variables you want to export
• Marking imported symbols in the DLL include file you distribute
This section discusses how you can address these issues when you create your DLL in
LabWindows/CVI. If you create your DLL in an external compiler, the approach is very
similar. The external compilers, however, do not agree in all aspects. This chapter also
discusses these differences.
Some of the information in this section is very technical and complex. Recommendations on
the best approaches to these issues are at the end of the section. These recommendations are
intended to make creating the DLL as simple as possible, and to make it easy to use the same
source code in LabWindows/CVI and the external compilers.
Calling Convention for Exported Functions
If you intend for only C or C++ programs to use your DLL, you can use the __cdecl or
Watcom stack-based calling convention to declare the functions you want to export. If,
however, you want your DLL to be callable from environments such as Microsoft Visual
Basic, you must declare the functions you want to export with the
__stdcall calling
convention.
You must do this by explicitly defining the functions with the _
_stdcall keyword. This is
true whether or not you choose to make _
_stdcall the default calling convention for your
00ProRef.book : 06chap03.fm Page 21 Monday, March 9, 1998 3:23 PM