Automatic winding generator C ++ / CLI

In our project, we have a significant amount of embedded C ++ code that we would like to use from a new level of user interface, which should be written in .Net.

I would like to use C ++ / CLI for this, and I saw that there is a pretty simple and pretty technical way to do this, wrapping the native classes with thin managed classes. I expect that I can find a tool that automates this task, because it seems to me that this is really a technical problem without a lot of the required โ€œhumanโ€ thinking.

There is such a tool that uses explicit p / invoke to do this - see http://www.swig.org/Doc1.3/CSharp.html . The point is that explicit p / invoke is more cumbersome and less efficient in performance.

Is there anyone familiar with such a tool?

Is there an inherent reason why such a tool is not yet available?

+8
interop c ++ - cli
source share
2 answers

The reason p / invoke is less efficient, because it should be a very universal interface for any function, knowing only the signature. Your hypothetical wrapping generator will not work better.

On the other hand, a developer encoding a custom wrapper class has much more information about functions that are used together, etc., and therefore can avoid a lot of slow and unnecessary conversions, for example, by storing values โ€‹โ€‹directly inside the wrapper and not converting them into some .NET format.

So, this does not mean that such an instrument is impossible, there is simply little use for it. If you care about performance, you write your own shell, complete with smart pointers for managing life time, etc.

Of course, p / invoke only provides access to the bare function. The fact that SWiG should be useful is to expose any interfaces of the C ++ class through bare exported functions.

I found one guide to the tool, which may be what you are looking for, although it looks pretty narrow in focus:

+7
source share

Explicit p / invoke is not necessarily bad. It really depends. The following links contain additional information that may interest you in reading. As with their specific examples, P / Invoke with suppressed security is faster than any other invocation methods in native DLLs, including C ++ / CLI.

http://rogue-modron.blogspot.com/2011/11/invoking-native.html

http://ybeernet.blogspot.com/2011/03/techniques-of-calling-unmanaged-code.html

We have a tool that may interest you. This is the C # shell generator for the C ++ DLL. Only C ++ DLLs compiled by VS are supported.

Using the tool, you can create a C # cover library directly from a DLL file and C ++ header files. It creates a Visual Studio project with all C # class files. All standard C ++ classes, template classes, native classes are supported. You do not need to write a single line of code.

Read more at the link below.

C # /. NET PInvoke Interop SDK

(I am the author of the tool)

+1
source share

All Articles