Вопрос

Based on the following C++ Header content:

typedef struct {
char    myVar[30][50];
}MyStruct;

extern "C" int   WINAPI  MyFunction(MyStruct *Configuration,int *CfgSize); 

I have looked for many examples over the internet but none uses a matrix variable inside a struct array as a parameter.
Can someone please tell me How to consume this function in C#?

Это было полезно?

Решение

In order to marshal this array member you just need to flatten it to the 1500 elements that it represents

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct MyStruct {

    /// byte[1500]
    [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=1500, ArraySubType=UnmanagedType.I1)]
    public byte[] myVar;
}

Do make sure to initialize the myVar array though manually when using in C#

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top