recieving UCHAR buffer in C# from C DLL
-
I have a C DLL that defines a structure like this
struct Data { int iLength; UCHAR *buff; // ... other data }; void AllocateData(Data *pData); void FreeData(Data *pData);
The buffer inside the structure is allocated inside the C DLL and the buffer lenght is provided in the iLength upon return. I want to use by creating C# marshalling layer to these function in C#. I have the declaration like this[ StructLayout( LayoutKind.Sequential )] public struct Data { public int iLength; //dont know what to use for UCHAR buffer // I tried byte[] buff; but it gives exceptions. //.. other data } [ DllImport( "Data.dll", EntryPoint="AllocateData", ExactSpelling=true, // Bypass A or W suffix search CharSet=CharSet.Ansi, // We want ANSI String CallingConvention=CallingConvention.Cdecl ) ] public static extern void AllocateData(ref Data data);
I cannot understand what to use for UCHAR pointer and how to allocate the structure before calling the DLL function.