Using __declspec( dllexport )

纵然是瞬间 提交于 2021-02-10 17:55:36

问题


Hi I'm little bit confused with dllexport.When I use __declspec( dllexport ) for example in class

 #define DllExport   __declspec( dllexport )  
class DllExport C {  
   int i;  
   virtual int func( void ) { return 1; }  
};  

do I export class C to dll file or do I export C class from dll file?


回答1:


When compiling the DLL you have to write __declspec(dllexport) as you did. This tells the compiler you want it to be exported. When using the DLL you want __declspec(dllimport) in your included files. The compiler then knows that this functions and classes are in a DLL-file and need to be imported. Because you don't want to change your header-files that much, you should define a macro e.g. BUILD_DLL.

    #ifdef BUILD_DLL
    #define DLL_PORTING __declspec(dllexport)
    #else
    #define DLL_PORTING __declspec(dllimport)
    #endif

Now you write in example.h:

    class DLL_PORTING example_class { … };

In your .exe file just include the header files you need and everything will work.



来源:https://stackoverflow.com/questions/48977138/using-declspec-dllexport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!