嗨,我有点困惑于dllexport.When,我在课堂上使用__declspec( dllexport )
#define DllExport __declspec( dllexport )
class DllExport C {
int i;
virtual int func( void ) { return 1; }
}; 我是将类C导出到dll文件,还是从dll文件导出C类?
发布于 2018-12-09 12:29:11
在编译DLL时,您必须像以前那样编写__declspec(dllexport)。这告诉编译器您想要导出它。使用DLL时,需要在所包含的文件中使用__declspec(dllimport)。然后编译器知道这个函数和类在DLL文件中,需要导入.因为你不想改变你的头文件太多,你应该定义一个宏,例如BUILD_DLL。
#ifdef BUILD_DLL
#define DLL_PORTING __declspec(dllexport)
#else
#define DLL_PORTING __declspec(dllimport)
#endif现在你用例子写字。
class DLL_PORTING example_class { … };在您的.exe文件中,只需包含所需的头文件,一切都会正常工作。
https://stackoverflow.com/questions/48977138
复制相似问题