I know I can use dll import + wrapping (managed) to use C++ libraries in C# applications ( question link>> ) but what's opposite? How can I use C# library in my C++ application? I'll handle events/operations/results in C# library but my application created with C++. For example here is my C++ application:
//In this example; Manager will be my C# library's instance, Log is a C# library's function that can print something. (That's only an example, not works. For describing something to understand my question)
int main()
{
if(MySystem.Start() == 0) //If there is no error
{
Manager.Log("System started successfully!"); //Post it to C# library!
}
return 0;
}
EDIT: Solution should be native C++. I'll not use C++\\CLI!
EDIT: Only c++ application will be native. Namely I can create a shared c++ library to handle C# library. C++ App.(Event) >> C++\\CLI Lib. >> C# Library , this way is posibble. Is there any example/topic/start point?
>> MY SOLUTION ( After answers, should be helpful for others ): I'll create a C++\\CLI shared library and I'll use it with my native C++ app. This library will handle my C# library ( more about in this question>> ). If I don't need C#, I'll re-code my C++\\CLI library as native library. I think that is pretty useful.
No CLI?
You can do it using Reverse P/Invoke
See http://tigerang.blogspot.co.il/2008/09/reverse-pinvoke.html .
CoreRT allows to compile native libraries for windows, linux and osx x64 platform this avoid to you use an C++ compatible layer. CoreRT uses NetCore, and NetCore doesn't support C++/CLI.
You will have to take care to expose your interface from the C# library to a C++-compatible layer.
Out of the top of my head, you could do two things:
Create a C API on top of your C# library (best way would be to add a C++/CLI layer to your library).
Create a COM interface to your C# library and use the library through COM objects.
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.