简体   繁体   English

在C#和C ++之间交换对象

[英]Exchanging objects between C# and C++

Imagine a project with a C# component and a C++ component. 想象一个包含C#组件和C ++组件的项目。 The C++ component is the old-school non .Net stuff (VC++ 6.0). C ++组件是老式的非.Net组件(VC ++ 6.0)。 What is an easy way to transfer objects between the two components? 在两个组件之间传输对象的简单方法是什么? I'm tempted to use System.Xml.XmlSerializer, but I'm not sure how to start getting at the .Net libraries with this old VC++ app. 我很想使用System.Xml.XmlSerializer,但是我不确定如何使用此旧VC ++应用程序开始使用.Net库。

Maybe there's an even easier way that I haven't considered. 也许我没有考虑过一种更简单的方法。 Any suggestions? 有什么建议么?

Have a look at C++/CLI. 看看C ++ / CLI。 You can write a wrapper with it that translates between both worlds. 您可以用它编写一个在两个世界之间转换的包装器。

How do you feel about using COM? 您对使用COM的感觉如何? .NET applications can both consume COM objects and can expose themselves as COM objects. .NET应用程序既可以使用COM对象,也可以将自己公开为COM对象。

使C ++成为COM对象?

If your C++ component is an unmanaged DLL exporting C-style functions "Platform Invoke" is another option. 如果您的C ++组件是导出C样式函数的非托管DLL,则“平台调用”是另一个选择。 This technic allows access from .NET (C#) managed code to the unmanaged C++ code but not in the other direction. 此技术允许从.NET(C#)托管代码访问非托管C ++代码,但不能从另一个方向访问。

根据项目的大小,我将使用VS 2008将VC6重新编译为C ++ / CLI。然后,您可以直接访问.net。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM