0

I'm using P/invoke to interoperate between C# and C++ in this project. I'd like to pass data structures that are symmetrically defined. What's the best infrastructure to use? Could protocol buffers be useful here?

Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166

2 Answers2

2

I would suggest to use C++/CLI since you can use the same header files / definition files in both worlds. One of the main goals for developing C++ CLI was to fill the gap between the managed and the unamanaged world. This article gives you even more advantages.

In the MSDN there is a nice description how C++cli works and how you can use it.

see also here

Community
  • 1
  • 1
schoetbi
  • 12,009
  • 10
  • 54
  • 72
1

If it's an option, you may want to look into using COM. Define .NET classes that are COM visible and have the InterfaceType ComInterfaceType.InterfaceIsDual, and decorate each parameter with the MarshalAs(UnmanagedType) attribute, then the C++ app can marshal objects that can be passed between managed and unmanaged code.

The "Symmetrical definition" is handled because the interface is defined in COM, plus COM gives you a little more error handling and visibility into what is going on than straight P/Invoke.

Guy Starbuck
  • 21,603
  • 7
  • 53
  • 64