2
votes

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
Hopefully the MSDN dllexport, dllimport information is of some help.Eljay
Normally you use a macro that switches between __declspec( dllexport ) when compiling the dll and __declspec( dllimport ) when using the dll. Like this: stackoverflow.com/questions/14980649/…drescherjm

1 Answers

3
votes

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.