What does this c++ class declaration mean?

前端 未结 2 1451
面向向阳花
面向向阳花 2020-12-12 00:18

I saw this piece of code in an article I am reading.

class EXAMPLEUNMANAGEDDLL_API CUnmanagedTestClass
{
public:
    CUnmanagedTestClass();
    virtual ~CUn         


        
相关标签:
2条回答
  • 2020-12-12 01:00

    This is for the purpose of exporting or importing the functions of a class into a DLL.

    Read this article on MSDN for additional information: Using dllimport and dllexport in C++ Classes

    The common practice is to use conditional compilation in the headers of the class, so that the same header can be used for producing the DLL or consuming the DLL:

    #ifdef EXAMPLEUNMANAGEDDLL_EXPORTS 
        #define EXAMPLEUNMANAGEDDLL_API __declspec(dllexport) 
    #else 
        #define EXAMPLEUNMANAGEDDLL_API __declspec(dllimport) 
    #endif 
    

    In this example, the code or the buildscripts of your library would define symbol EXAMPLEUNMANAGEDDLL_EXPORTS.

    0 讨论(0)
  • 2020-12-12 01:11

    Such constructs are used in Windows to control whether the class is being used while building a DLL or it is being used to build a user of the DLL.

    When building the DLL, EXAMPLEUNMANAGEDDLL_API needs to expand to __declspec(dllexport).

    When buidling users of the DLL, EXAMPLEUNMANAGEDDLL_API needs to expand to __declspec(dllimport).

    Further information can be found at:

    1. Exporting from a DLL Using __declspec(dllexport)
    2. Importing into an Application Using __declspec(dllimport)
    0 讨论(0)
提交回复
热议问题