zoukankan      html  css  js  c++  java
  • .def文件与__declspec(dllexport)

    A module-definition (.def) file is a text file containing one or more module statements that describe various attributes of a DLL. If you are not using the __declspec(dllexport) keyword to export the DLL's functions, the DLL requires a .def file.
    A minimal .def file must contain the following module-definition statements:
    The first statement in the file must be the LIBRARY statement. This statement identifies the .def file as belonging to a DLL. The LIBRARY statement is followed by the name of the DLL. The linker places this name in the DLL's import library.

    The EXPORTS statement lists the names and, optionally, the ordinal values of the functions exported by the DLL. You assign the function an ordinal value by following the function's name with an at sign (@) and a number. When you specify ordinal values, they must be in the range 1 through N, where N is the number of functions exported by the DLL. If you want to export functions by ordinal, see Exporting Functions from a DLL by Ordinal Rather Than by Name as well as this topic.
    For example, a DLL that contains the code to implement a binary search tree might look like the following:

    LIBRARY   BTREE
    EXPORTS
       Insert   @
    1
       Delete   @
    2
       Member   @
    3
       Min   @
    4

    Microsoft introduced __export in the 16-bit compiler version of Visual C++ to allow the compiler to generate the export names automatically and place them in a .lib file. This .lib file can then be used just like a static .lib to link with a DLL.

    In newer compiler versions, you can export data, functions, classes, or class member functions from a DLL using the __declspec(dllexport) keyword. __declspec(dllexport) adds the export directive to the object file so you do not need to use a .def file.
    This convenience is most apparent when trying to export decorated C++ function names. Because there is no standard specification for name decoration, the name of an exported function might change between compiler versions. If you use __declspec(dllexport), recompiling the DLL and dependent .exe files is necessary only to account for any naming convention changes.
    Many export directives, such as ordinals, NONAME, and PRIVATE, can be made only in a .def file, and there is no way to specify these attributes without a .def file. However, using __declspec(dllexport) in addition to using a .def file does not cause build errors.
    To export functions, the __declspec(dllexport) keyword must appear to the left of the calling-convention keyword, if a keyword is specified. For example:

    __declspec(dllexport) void __cdecl Function1(void);

    To export all of the public data members and member functions in a class, the keyword must appear to the left of the class name as follows:

    class __declspec(dllexport) CExampleExport : public CObject
    {  
    class definition };



    Reference:
    1. http://msdn.microsoft.com/en-us/library/d91k01sh(VS.80).aspx 
    2. http://msdn.microsoft.com/en-us/library/a90k134d(VS.80).aspx

  • 相关阅读:
    隐藏Nginx、Apache、PHP的版本信息
    PHP 安装版本选择
    Python 队列实现广度搜索算法 附上迷宫实例
    PHP 利用栈实现迷宫算法
    Python 和 PHP 实现 队列 和 栈 以及 利用栈实现符号匹配算法
    tp5 安装migration 报错 Installation failed, reverting ./composer.json to its original content.
    Redis 有序集合
    Redis 集合命令记录
    ‘This support library should not use a different version’解决方案
    build.gradle文件详解(二)
  • 原文地址:https://www.cnblogs.com/whyandinside/p/1560948.html
Copyright © 2011-2022 走看看