Warning: count(): Parameter must be an array or an object that implements Countable in /home/devartplus/devartplus.com/wp-content/plugins/maxblogpress-ping-optimizer/maxblogpress-ping-optimizer.php on line 455

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Archive

Archive for the ‘C++/CLI’ Category

How to marshall C++ reference parameter to C#.NET using C++/CLI

May 11th, 2011 No comments

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Suppose you have some very complicate function written in either C or native C++. And suppose you want to use it in your C#.NET managed code. Obviously, marshalling is required.
There are generally 3 possible options for marshalling:
1) COM
3) C++/CLI
2) Pinvoke (Platform Invokation)

Since making a COM wrapper for native code (ATL e.t.c) is not trivial, and C++/CLI is usually used for more complicated cases, most used way is platform invokation: define the function as “static extern”, add “DllImport” attribute, define some parameters and – eureka! – the required managed function is ready for using…
In case of native C++ class’s method, the process is a bit more complicated, because compiler concatenates a class & method names in some strange form. Still, the new method name could be acheived using known for all “Dependency Walker” application.

Read more…

Categories: .Net, C#, C++/CLI Tags: ,