[Mono-devel-list] P/Invoke question

Marcus mathpup at mylinuxisp.com
Sun Aug 22 19:18:46 EDT 2004


No, Mono does not appear to marshal the data correctly when passing a 
reference to an array of strings. The C# signature should be

	private static extern int f(ref string[] data);

if the C++ function is

	int f(char ***data);

I did not realize that Mono didn't support this properly until you mentioned 
it because I was testing on Linux using Rotor (MS's "shared source" version 
of .NET).

If you recall, I mentioned in a previous email that the CLI spec only 
addresses a limit set of data types that must be marshaled, and "ref 
string[]" is not one of them. Integer and floating point types, enums, 
strings, and pointers to them are required to be supported in both directions 
(managed -> unmanaged and unmanaged -> managed). Arrays and delegates are 
required to be supported in managed -> unmanaged, but not required to be 
suppoted from unmanaged -> managed. Obviously .NET goes beyond these 
requirements, but Mono does not implement this particular case.

Although it isn't a bug per se, the Mono developers should probably be 
informed about this. You could file a bug report about this. Or I can if you 
would prefer.

Marcus



> Marcus:
> Thanks for the code snippets.  However, I could not get them to work 
> properly.  data.cpp compiles and runs fine standalone, and compiles fine 
> as a shared lib, however, whenever data.cs calls it, garbage is 
> returned.  Maybe I'm doing something silly.



More information about the Mono-devel-list mailing list