简体   繁体   English

C#中的C ++库-继承类

[英]C++ library in C# - Inherit Classes

I'm trying to use a C++ library (GAlib) in my C# project, in Visual Studio 2010. 我正在尝试在Visual Studio 2010的C#项目中使用C ++库(GAlib)。

I built the library to get the .lib and, thanks for your useful advice: 我构建了该库以获取.lib,并感谢您的有用建议:

Using c++ library in c# 在C#中使用C ++库

I'm able to call the functions but I not able to create classes inheriting from the ones present within the library. 我可以调用这些函数,但无法创建从库中存在的类继承的类。

I have followed this guide 我已遵循本指南

http://blogs.msdn.com/b/vcblog/archive/2008/12/08/inheriting-from-a-native-c-class-in-c.aspx http://blogs.msdn.com/b/vcblog/archive/2008/12/08/inheriting-from-a-native-c-class-in-c.aspx

I added 我加了

__declspec(dllexport) class GAEvalData {
public: 
. . . 
}

but using dumpbin /EXPORT ga.lib to achieve the EntryPoint, I have no info. 但是我没有使用dumpbin / EXPORT ga.lib来实现EntryPoint的信息。

I report the dumpbin output: 我报告dumpbin输出:

Dump of file ga.lib
File Type: LIBRARY

And nothing else. 没别的。

Also inverting 也反转

class __declspec(dllexport) GAEvalData {
public: 
. . . 
}

it seems no work. 似乎没有工作。

Any suggestions? 有什么建议么?

Is this the best way to inherit classes from external libraries? 这是从外部库继承类的最佳方法吗?

Thanks in advance, 提前致谢,

Dave 戴夫

Normally you should declare your class similar to: 通常,您应该声明您的类,类似于:

#ifdef DBTOOL_EXPORTS
#define DBTOOL_API __declspec(dllexport)
#else
#define DBTOOL_API __declspec(dllimport)
#endif

class DBTOOL_API Class {}

Your C++ dll should define DBTOOL_EXPORTS. 您的C ++ dll应该定义DBTOOL_EXPORTS。 I think the idea is clear. 我认为这个想法很明确。 Hopefully it will help 希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM