我正在尝试在 C# 中构建一个结构以传递给非托管 C++,我想知道unichar
在我的结构中用于数组的正确变量类型是什么以及它应该被编组为什么。
我已经想通了unsigned char array
C/C++
typedef struct _foo {
void *fileId;
unsigned char fileName[15];
} foo;
C#
[StructLayout(LayoutKind.Sequential)]
public struct foo
{
public IntPtr fileId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
public string fileName;
}
所以如果我在 C++ 中有以下内容
typedef struct _foo {
void *fileId;
unichar fileName[15]; // UTF-16LE
} foo;
在 C# 中使用的正确结构是什么?