[英]Why can't I use __declspec(dllexport) to export DllGetClassObject() from a COM DLL?
[英]DLL: Can I use __declspec(dllexport) when SDK header file doesn't use it
我正在使用一个SDK,期望我的DLL导出某些功能。 SDK提供了类似于以下要导出功能的头文件:
#ifdef __cplusplus
extern "C" {
#endif
HRESULT extern WINAPI Foobar();
#pragma pack(pop)
#ifdef __cplusplus
} /*extern "C"*/
#endif
https://github.com/sergiofst/wosa-xfs-spi-base-framework/blob/master/depends/INCLUDE/XFSSPI.H
我的问题是,我没有发现如何在提供程序(dllexport)端使用此标头,因为每次我尝试添加__declspec(dllexport)
:
__declspec(dllexport) HRESULT WINAPI Foobar() {
...
}
我收到error C2375: 'Foobar': redefinition; different linkage
error C2375: 'Foobar': redefinition; different linkage
。
那么,有什么方法可以使用SDK提供的头文件,还是必须使用def文件或复制/编辑函数定义?
最好的祝福。
最简单,最愚蠢,最明显的方法是将头文件复制到您的项目中,并向其中添加dllexport。
下一个方法是在实现该方法的文件中不包括头文件。
然后是我希望其他人回答的.def文件。
或者,您可以尝试将/ EXPORT:Foobar添加到link.exe命令行中。 有关详细信息,请参见https://docs.microsoft.com/zh-cn/cpp/build/reference/export-exports-a-function 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.