Recently want to write good C + + code to do C # interface, online check the automatic packaging tools.
There are 4 ways to summarize:
1. Use Invoke to refer to a C + + write dll directly in C #. This method is suitable for simple cases where the complexity of the code is too large.
2. Write COM to use the DLL, familiar with COM technology can be tried.
3. Use CLR C + + (also known as managed C + +). This technique adds meta information to C + + and automatically manages pointers, much like C #. But it's basically like getting a newly learned language (the cost is a bit high). Then, based on Microsoft's Common Language Infrastructure (Cli,common Language Infrastructure), all languages (including C #) are converted into this intermediate format, and of course C # can invoke the code.
4. CLI technology is also used, but C + +/CLI. The difference is that this is just a package for C + + code, and the code is not too high. Is the author's most recommended way.
Said to keep the implementation of the way, now the automatic packaging tools. If you want to write your own code, even if you write only the encapsulated interface, in the face of large-scale engineering is also unbearable. Because the code you write is maintained. The Auto-encapsulation tool then comes in handy. Currently I have Google to 4 tools:
PInvoke this only with C + + header files and compiled DLL can complete the package, it should be C + +/CLI mode. and free.
Xinterop This is generated from the header file, it should be in C + +/CLI mode, and supports bidirectional invocation (that is, C # can invoke C + + code, C + + code can also call C # code). There is no open source or free information on the website.
SWIG is the top of the comparison name. Interfaces for C + + can be provided in many languages, such as scripting language Javascript, Perl, PHP, Python, TCL and Ruby, non-scripting language C #, Common Lisp (Clisp, Allegro CL, Cffi, Uffi), D , Go language, Java including Android, Lua, Modula-3, OCAML, Octave, Scilab and R. However, the information provided by the C++class class is insufficient.
Mono/c# is an open source tool that is hosted on GitHub and provides C # access for C + + code. Mono is an open source C # implementation (not owned by Microsoft) and is cross-platform. Unity3d is using Mono's C # interface.
Let's start with a brief and detailed comparison in the future.
C # C + + Automatic interface tool