Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there,
I wrote in C a struct like that
C++

struct IMAGE {
    unsigned int    x, y;
    unsigned char   **data;
};


Could anybody please tell me how to marshall this struct to use in C#?

my solution does not work.
C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class IMAGE
{
            public UInt32 x;
            public UInt32 y;

            public byte[][] data;
};
Posted

1 solution

Hi, change declaration of struct to follow:

C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class IMAGE
{
            public UInt32 x;
            public UInt32 y;

            public IntPtr data;
};


and for IntPtr to string use methods:

C#
public static string[] PtrToStringArray (IntPtr stringArray)
         {
            if (stringArray == IntPtr.Zero)
              return new string[]{};

            int argc = CountStrings (stringArray);
            return PtrToStringArray (argc, stringArray);
         }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900