Admin Production ni-theme
Current Publication

Marking Imported Symbols in an Include File Distributed with a DLL

LabWindows/CVI

Marking Imported Symbols in an Include File Distributed with a DLL

If your DLL might be used in a C or C++ environment, you must distribute an include file with your DLL. The include file must declare all the symbols the DLL exports. If any of these symbols are variables, you must mark them with an import qualifier. Variable declarations require import qualifiers so the compiler can generate the correct code for accessing the variables.

You can use import qualifiers on function declarations, but they are not necessary. When you use an import qualifier on a function declaration, compilers can generate slightly more efficient code for calling the function.

Using import qualifiers in the include file you distribute with your DLL can cause the following problems if you use the same include file in the DLL source code.

  • If you mark variable declarations in the include file with import qualifiers and you use the include file in a source file other than the one in which you define the variable, LabWindows/CVI and other compilers treat the variable as if it were imported from another DLL and generate incorrect code as a result.
  • If you use export qualifiers in the definition of symbols and the include file contains import qualifiers on the same symbols, some compilers report an error.

You can solve these problems in the following ways:

  • You can avoid exporting variables from DLLs and thereby eliminate the need to use import qualifiers. For each variable you want to export, you can create functions to get and set its value or a function to return a pointer to the variable. You do not need to use import qualifiers for functions. This is the simplest approach and works in LabWindows/CVI. However, this method does not work if you use an export qualifier in a function definition and you create the DLL with a compiler that requires the declaration to use the same qualifier.
  • You can create a separate include file for distribution with the DLL.
  • You can use a special macro that resolves to either an import or export qualifier depending on a conditional compilation flag. In LabWindows/CVI, you can set the flag in your DLL project in the Compiler Defines section of the Build Options dialog box.