[MonoDevelop] [Mono-list] marshal a struct

Michael Hutchinson m.j.hutchinson at gmail.com
Mon Oct 6 00:08:28 EDT 2008


On Fri, Oct 3, 2008 at 6:52 AM, Norbert Lazzeri <elnogge at gmx.de> wrote:
> seems like you where right. i changed the struct on the c#-side to:
>
> /*****************/
> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
> public struct INFO
> {
>    public int size;
>    [MarshalAs(UnmanagedType.ByValArray,SizeConst=100)]
>    public byte [] data;
>    public bool flag;
> }
> /*****************/
> also i found a codesnipped on the net:
> /*****************/
> public static string convertDllData(byte[] mybuffer){
>        StringBuilder temp = new StringBuilder();
>        int counter = 0;
>
>        for(int i = 0; i < mybuffer.Length; i++){
>            if(mybuffer[i] != 0x00)
>            {
>                temp.Append( Convert.ToChar(mybuffer[i]));
>                counter++;
>            }
>            else{
>                break;
>            }
>        }
>        return temp.ToString();
>    }
> /*****************/
> it does nothing else than adding only those chars to the StringBuilder
> that are not null-Characters. using this code everthing works just fine
> allthough its very ugly i think..
>
> i also tried to convert the byte-array to a string using
> Encoding.ASCII.getString() and some other methods from Encoding but the
> problem remains here..
>
>
> is this a well known bug of monodevelop or should i better file a bug?

I'm not aware of a bug report for that, so could you file it please?

Thanks,

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list