0

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?

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.