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