本文介绍了在C#中封送C数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际C结构:
Actual C structures:
typedef struct procedure
{
char code[8];
}procedure;
typedef struct p45_cldxed24
{
procedure p45_cldxed[8];
}p45_cldxed24;
p45_cldxed24的等效C#结构将是什么?具体来说,你如何编组数组?
What would be the equivalent C# structure for p45_cldxed24? Specifically, how would you marshal the array?
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct p45_cldxed24
{
[MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct,SizeConst = 8,SizeParamIndex=0)]
procedure[] p45_cldxed;
}
推荐答案
我相信代码将是如下:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct p45_cldxed24
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
procedure[] p45_cldxed;
}
这里的关键是 MarshalAs
属性。
这篇关于在C#中封送C数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!