c# - 如何编码包含 char 矩阵的数组结构

标签 c# c++ marshalling com-interop

基于以下 C++ header 内容:

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

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

我在互联网上查找了很多示例,但没有一个示例使用结构数组 中的矩阵变量 作为参数。
有人可以告诉我如何在 C# 中使用此函数吗?

最佳答案

为了编码这个数组成员,你只需要将它展平到它代表的 1500 个元素

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

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

在 C# 中使用时,请务必手动初始化 myVar 数组

关于c# - 如何编码包含 char 矩阵的数组结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18874447/

相关文章:

c# - 不确定我是否正确使用了多态性,如果可以,我只能调用父类中的方法

c# - __builtin_popcount - 这在 C# 中是否等效?

c++ - QTableWidget中如何动态分配单元格

java - 如何在没有堆错误的情况下将大型 java 对象编码为 xml?

json - 从 Map 和 Struct 编码的 JSON 中的排序差异

c# - SQLite typeof() 也应该与 SQL 一起工作吗?

c# - 如何处理 System.CannotUnloadAppDomainException?

c++ - C/C++ : do built-in objects such as `int` `double` always stay in the exact place within memory in the duration of the program?

android - 如何在安卓上使用QFile?

xml - 转到XML编码(marshal): Unintended Output of Slice