How do I call managed .NET code from my unmanaged C ++ code on Windows and vice versa?

I have a clean C ++ application developed using VC 6.0. I would like this application to use a library developed in C #. How do I call methods in a C # library from my own executable? I don't want to convert my own managed C ++ managed code application to managed code. In the same way, how can I do the opposite? Is PInvoke the only option? I would appreciate any links or pointers for the same.

+3
source share
2 answers

To call managed code from unmanaged C ++, use ClrCreateManagedInstance or export your types in your managed assembly as COM visible, and use COM. To call unmanaged code from managed, use COM or P / Invoke.

+3
source

In the main line of Microsoft, this uses COM interaction. There is another option, sometimes called "Reverse P / Invoke", there is an interesting blog post here and a few more here

In addition, if you have Delphi.NET (now non-existent), this language allows you to export static methods, for example, any DLL function, then you can call the Delphi.NET assembly like a regular native Dll.

+1

Source: https://habr.com/ru/post/1711303/


All Articles