George Silva
George Silva

Reputation: 3484

How to create a c# wrapper for a software in VC++?

I need to create a VC++ wrapper in C#. Is there a way to automatically generate the code?

Edit: let me clarify a bit: I have a simple project with complicated math functions (computing magnetic declination) in c++. Its just three files, one header, one command line controller and the library.

I was looking at SWiG but I found it to be enigmatic :P. I'm taking a look at C++/CLI.

Any tips and pitfalls to watch for?

Upvotes: 0

Views: 1282

Answers (4)

Achim
Achim

Reputation: 15702

As for most short questions: It depends on your settings and requirements! ;-) If you have a more C style interface, you might be able to solve your problem just by using Interop. If "real" OO progamming and C++ are involved, you probably have to look at C++/CLI. That can be easy, but it can also become painful - depending on your classes. As far as I know, there's not automatic code generation tool.

Upvotes: 1

Sauleil
Sauleil

Reputation: 2603

You can have a look at this tutorial:

http://www.codeguru.com/csharp/csharp/cs_data/article.php/c4217

I think it's better if you make your own wrapper than using any tool (if it does exists). The reason is that you can create a better C# wrapper using the right philosophies instead of generating a list of function call from a DLL.

And for the pitfalls, the only thing I can say is that since you are going to mix manage and unmanaged class, be sure that your struct/parameters are matching (sizeof or types).

Upvotes: 1

Ben Voigt
Ben Voigt

Reputation: 283634

SWiG supports C#. But a C++/CLI wrapper will be much more ".NET-like" than one automatically generated by SWiG.

Upvotes: 1

HABJAN
HABJAN

Reputation: 9338

Take a look at: Using Unmanaged C++ Libraries (DLLs) in .NET Applications

Or you can use C++/CLI

Upvotes: 1

Related Questions