简体   繁体   中英

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?

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.

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

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).

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