문제

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