How to I call a C++ function from my C# class with the following signature?

int MyFunc(MyStructure **)

typedef struct MyStructure
{
  unsigned char ID[16];
  unsigned int* Path;
  AnotherStructure *Format;
}

typedef struct AnotherStructure
{
  short Owner;
  short Type;
}

I attempted the following in C#...

public struct MyStruture
{
  public fixed byte ID[16];
  uint* Path;
  IntPtr Format;
}

[DllImport("MyFunc.DLL")
internal static extern int MyFunc(IntPtr pStructure)

MyStructure[] Arr=new MyStructure[16];
int iSize=Marshal.Sizeof(typeof(MyStructure))*16;

IntPtr pStructure=Marshal.AllocHGlobal(iSize);
Marshal.StructureToPtr(Arr, pStructure, false);

int iRes=MyFunc(IntPtr);

Marshal.FreeHGlobal(pStructure);

I get an error "The specified structure must be blittable or have layout information.
Parameter name: structure"

Any suggestion?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.