Microsoft 专用
dllexport
dllimport存储类属性是 C 和 C++ 语言Microsoft特定的扩展。 可以使用它们来导出和导入 DLL 中的函数、数据和对象。
语法
__declspec( dllimport )declarator
__declspec( dllexport )declarator
注解
这些属性显式定义 DLL 的接口到其客户端,可以是可执行文件或其他 DLL。 将函数声明为 dllexport 不需要模块定义 (.def) 文件,至少与导出函数的规范有关。 该 dllexport 属性替换关键字 __export 。
如果标记 __declspec(dllexport)类,则类层次结构中类模板的任何专用化都隐式标记为 __declspec(dllexport)。 这意味着显式实例化类模板,并且必须定义类的成员。
dllexport 函数的 公开其修饰名称(有时称为“名称混乱”)的函数。 对于C++函数,修饰的名称包括编码类型和参数信息的额外字符。 声明为 extern "C" C 名称修饰规则的 C 函数或函数。 有关 C/C++ 代码中的名称修饰的详细信息,请参阅 修饰名称。
若要导出未编码的名称,可以使用定义节中EXPORTS未编码名称的模块定义 (.def) 文件进行链接。 有关详细信息,请参阅 EXPORTS。 导出未编码名称的另一 #pragma comment(linker, "/export:alias=decorated_name") 种方法是在源代码中使用指令。
声明或dllimport声明dllexport时,必须使用扩展属性语法和__declspec关键字。
示例:
// Example of the dllimport and dllexport class attributes
__declspec( dllimport ) int i;
__declspec( dllexport ) void func();
或者,若要使代码更易于阅读,可以使用宏定义:
#define DllImport __declspec( dllimport )
#define DllExport __declspec( dllexport )
DllExport void func();
DllExport int i = 10;
DllImport int j;
DllExport int n;
有关详细信息,请参见:
结束 Microsoft 专用