C#库到本机C ++应用程序 [英] C# library to native C++ application

查看:174
本文介绍了C#库到本机C ++应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用dll import + wrap(托管)在C#应用程序中使用C ++库(问题链接>> )但什么是相反?如何在我的C ++应用程序中使用C#库?我将处理C#库中的事件/操作/结果,但我的应用程序用C ++创建。例如这里是我的C ++应用程序:



//在这个例子中; Manager将是我的C#库的实例,Log是一个C#库的函数,可以打印一些东西。 (这只是一个示例,无效,用于描述可以理解我的问题的内容)

  int main()
{
if(MySystem.Start()== 0)//如果没有错误
{
Manager.Log !); //发布到C#库!
}
return 0;
}

EDIT:

编辑: 只有c ++应用程序将是本机的。也就是说,我可以创建一个共享的c ++库来处理C#库。 C ++应用程序(事件)>> C ++ \CLI Lib。 >> C#Library ,这种方式是posibble。是否有任何示例/主题/起点?



>>我的解决方案(回答后,应对其他人有用): 我将创建一个C ++ \CLI共享库,我将使用它与我的本地C + +应用程序。此库将处理我的C#库(有关此问题的详情>> )。如果我不需要C#,我将重新编码我的C ++ \CLI库作为本地库。我认为这是非常有用的。

解决方案

你必须注意将你的接口从C#兼容层。



除了我的头,你可以做两件事:




  • 在C#库之上创建一个C API(最好的方法是在您的库中添加C ++ / CLI层)。


  • p>为您的C#库创建一个COM接口,并通过COM对象使用该库。



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.

解决方案

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.

这篇关于C#库到本机C ++应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆