#pragma import

Under AIX, this pragma is not available for C, but it is available for C++.

Description

The #pragma import directive lets you import a function or a variable from a DLL using either an ordinal number or a name different from the one that it has in the DLL.

Syntax

 

Ordinals are not supported in AIX; everything is by name.

The identifier is the name you use in your source to refer to the function or variable. The "export_name" is the name of the function or variable in the DLL.

For C++ files, "export_name" can also be a function prototype. If "export_name" is not specified, it is assumed to be the same as identifier.

If the identifier is the name of an overloaded function or a member function, there is a risk that the pragma will override the compiler-generated names. This will create problems during linking.

Note: Both identifier and "export_name"must be defined only once in each compilation unit.

The "module" is the name of the DLL containing the identifier, and ordinal indicates the position of the function or variable within the DLL. Ordinal numbers are described in more detail in the Toolkit documentation.

The information provided by #pragma import is used at load time to locate the imported identifier. If ordinal is 0, the "export_name" is used to find the identifier. If ordinal is any other number, "export_name" is ignored and the identifier is located by number. It is usually faster to locate the identifier by number than by name. By default, ordinal has a value of 0

Note: You cannot use the ordinals provided in the Toolkit header files with #pragma import. These ordinals are provided as C macros that cannot be used in #pragma directives.

If an identifier is specified in more than one #pragma import, all instances of the pragma must have the same "export_name", module, and ordinal value. If the export name, module name, or ordinal value are different, an error will occur.

For example, the following imports "Joe" from the "TeamList":

#pragma import(player, "Joe", "TeamList", 2) 


Preprocessor Directives - An Overview
Preprocessor Directive - #pragma