[英]Importing a C# class library into Visual C++
I have a C# class library that contains methods that need to be used with an external application. 我有一个C#类库,其中包含需要与外部应用程序一起使用的方法。 Unfortunately this external application only supports external APIs in C/C++.
不幸的是,此外部应用程序仅支持C / C ++中的外部API。
Suppose I have a takeIntReturnDoubleArray method in this C# library that takes an integer and returns an array of doubles. 假设我在这个C#库中有一个takeIntReturnDoubleArray方法,该方法采用一个整数并返回一个双精度数组。 All I need to do is have a C++ method that takes an integer, calls the C# library and returns an array of doubles to the calling application.
我需要做的就是拥有一个采用整数的C ++方法,调用C#库并将双精度数组返回给调用应用程序。
So in essence the C++ library is just acting as an intermediary between the C# wrapper and the external application. 因此,从本质上讲,C ++库只是充当C#包装程序和外部应用程序之间的中介。
Is there an easy way to do this? 是否有捷径可寻? Do I have to do anything special on the C# side to allow it to be imported into C++ easily?
我是否需要在C#方面做一些特殊的事情才能将其轻松导入C ++? I have seen some talk of using the #import statement but I really have no idea what I am doing when it comes to C++.
我已经看到过一些关于使用#import语句的讨论,但是我真的不知道在C ++中我在做什么。
What is the approach I should be taking here? 我在这里应该采取什么方法?
You have two main options here: 您在这里有两个主要选择:
COM Interop is one way to approach this problem. COM Interop是解决此问题的一种方法。 You'll have to have a COM layer for the C# library function(s) you want to expose to the C++ application.
您必须具有要暴露给C ++应用程序的C#库函数的COM层。 This ( http://msdn.microsoft.com/en-us/library/aa302324.aspx#usingframeworktools_topic10 ) might be of interest.
这个( http://msdn.microsoft.com/en-us/library/aa302324.aspx#usingframeworktools_topic10 )可能很有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.