views:

273

answers:

3

Hello,

I'm trying to marshall unsigned char** (which is in a C++ interface) in order to call the method from C#.

How can this be done? Is there a list where are C++ data types and C# data types?

Thanks!

A: 

That would be marshalable as ref string. Be sure to use the right character set with a [MarshalAs] attribute.

ErikHeemskerk
+2  A: 

What is the semantics of this unsigned char**? If it is a byte array, use ref byte[]. If it is a zero terminated string, use ref string.

You can find some popular method signatures mapped to c# on the page http://www.pinvoke.net, which may give you the idea.

codymanix
In the C++ interface is this sentence: "This [unsigned char**] is an array of pointers to arrays of characters. Each character is one of the standard XSB characters.". This variable should serve for storing positions of objects in Sokoban game. Thank you!
MartyIX
in that case string[] should fit.
codymanix
It works. Thank you!
MartyIX
+1  A: 

I think you should use a serialization library that has an interface for both C++ and C#.

Both Protocol Buffers from Google or Thrift from Facebook support these two languages.

It would definitely make things much easier and safer for you.

If you decide to change the transferred data types (i.e. use integers, structures, etc. instead of raw strings), using a serialization library is the way to go.

the_void
Thank you for links! But this is the last data type I need so I would be very happy just to marshall it and continue with other work :)
MartyIX
When you have some spare time I would really advise you look over it. It seems the perfect use case for your project, because you are exchanging different message types. With Protocol Buffers, changing the message structure or the interface is very easy. Here is a tutorial to get you started with C#: http://snipplr.com/view/24475/google-protocol-buffers-usage-in-c-using-jon-skeets-protobufcsharpport/. You can even use it from within the Visual Studio IDE: http://code.google.com/p/protobuf-net/.
the_void