[Mono-dev] C->C#, how to pass a byte[] parametr

Paolo Molaro lupus at ximian.com
Tue Mar 28 07:56:21 EST 2006


On 03/27/06 vavra at software602.cz wrote:
>  I'd like to pass from C  a buffer of binary data to C# code.
> 
> Using directly char* doesn't seem to me as a right way ...

If the managed method takes a byte* you can pass a char* (note that in
C# a char is a two-byte integer). If the managed method takes a byte[]
(a byte array) you need to provide it; create it with:

	MonoArray *array = mono_array_new (mono_domain_get (), mono_get_byte_class (), length);

and then fill the contents:

	memcpy (mono_array_addr (array, char, 0), my_data, length);

and pass the array object (where my_data is the pointer to the data you
want to put in the array and length is the size of the data).

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list