1

I have a solution with 2 projects:

  1. a c++ main project
  2. a c# project (display simulator)

Today these 2 apps share data using a loopback TCP client/server connection, but that's not very optimal (timing issues..).

I was wondering if there was a way to access the c# data from the c++ project directly and vice versa? (It seems to be possible with 2 c# projects..) If it's not possible, what's the best way to implement this with shared memory?

thanks! Michael

EDIT: thanks for the answers. The 2 projects used to be independant solutions and are both executables - I'm actually trying to merge the 2 into 1 solution / executable. For info: The c++ app is a PC version of an embedded app - the c# app is a lcd/HMI simulator.

4

4 回答 4

1

将 C++ 项目转换为 C++/CLI 项目可能是最简单的方法。但是请注意,有些代码不能很好地与 C++/CLI 配合使用(我们在使用托管可执行文件中使用 boost::thread 的库时遇到了问题)。

于 2009-11-18T12:06:03.017 回答
0

You can use COM Interop or Platform Invoke to access native code in C#.

If that's not what you're asking for, please elaborate.

于 2009-11-17T22:17:48.187 回答
0

Named Pipes?

For interprocess communication via named pipes you can check out the .NET 3.5 feature http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx for the C# side. From the C++ side, I assume you know the equivalent :).

于 2009-11-17T22:20:32.720 回答
0

我知道有两种方法可以直接访问 c++ 和 c# 之间的内存,而无需编组/解编组和 com 的开销。如果需要将代码的 c++ 部分保持为本机,那么我知道实现此目的的唯一方法是从您的 c++ 应用程序托管 clr。一项相对复杂的工作。谷歌“托管公共语言运行时”。然后您可以将您的 c# 代码作为程序集加载,调用 c# 代码并提供一个通用的共享内存样式接口。尽管您必须自己编写所有共享内存支持,因为我发现在 c#/.net 中没有对共享内存的直接支持。

另一种方法是使用公共语言运行时支持编译您的 c++ 代码。到目前为止,这要容易得多,它将让您获得 c++ 的所有功能和荣耀,同时允许访问基于 clr 的数据类型,以及在 c++ 和 c# 代码之间来回调用的能力。请参阅 VS2008 文档中的“针对 CLR 的语言功能”。pin_ptr 将成为您在此过程中的亲密朋友和盟友。

于 2009-11-18T10:33:28.820 回答