C++ class in DLL to be imported to C#

G

Guest

Dear all,

I am trying to write a class in C++, exported it in DLL.
Does anyone know how I can import them in C#?

For example:
in C++
class DllExport Abc
{
public:
int foo1;
FILETIME anytime;
};


in C# I would like to access the member variables like this.
....
Abc abc;
abc.foo1=10;

How can I do so? Which version of visual studio should I use to build the
DLL and C# program?

Thanks

Tony Siu Chun Tung
 
M

Mattias Sjögren

I am trying to write a class in C++, exported it in DLL.
Does anyone know how I can import them in C#?

You would have to write a wrapper class in managed C++, C# can't
directly use native C++ classes.


Mattias
 
G

Guest

Dear Mattias,

I am not familiar with managed C++
Could you give us an example of how to write the warpper class for warpping
a class like this? In Which Visual Studio should I write it in?

class DllExport Abc
{
public:
int foo1;
FILETIME anytime;
};

Thanks alot

Tony
 
W

Willy Denoyette [MVP]

Search the MSDN docs for "C++ Interop" and you get a bunch of examples.
http://msdn2.microsoft.com/en-us/library/2x8kf7zx(VS.80).aspx

Willy.

| Dear Mattias,
|
| I am not familiar with managed C++
| Could you give us an example of how to write the warpper class for
warpping
| a class like this? In Which Visual Studio should I write it in?
|
| class DllExport Abc
| {
| public:
| int foo1;
| FILETIME anytime;
| };
|
| Thanks alot
|
| Tony
|
|
|
| "Mattias Sjögren" wrote:
|
| > > I am trying to write a class in C++, exported it in DLL.
| > >Does anyone know how I can import them in C#?
| >
| > You would have to write a wrapper class in managed C++, C# can't
| > directly use native C++ classes.
| >
| >
| > Mattias
| >
| > --
| > Mattias Sjögren [C# MVP] mattias @ mvps.org
| > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| > Please reply only to the newsgroup.
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top