简体   繁体   中英

C++ library in C# - Inherit Classes

I'm trying to use a C++ library (GAlib) in my C# project, in Visual Studio 2010.

I built the library to get the .lib and, thanks for your useful advice:

Using c++ library in 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

I added

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

but using dumpbin /EXPORT ga.lib to achieve the EntryPoint, I have no info.

I report the dumpbin output:

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. I think the idea is clear. Hopefully it will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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