编组C数组在C# [英] Marshaling C arrays in C#
本文介绍了编组C数组在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
编组C结构的C#
实际的C结构:
typedef结构的过程
{
字符code [8]。
}程序;
typedef结构p45_cldxed24
{
过程p45_cldxed [8];
} p45_cldxed24;
什么是等价的C#结构p45_cldxed24?具体来说,您将如何封送数组?
这是正确的?
[StructLayout(LayoutKind.Sequential,字符集= CharSet.Ansi)
结构p45_cldxed24
{
[MarshalAsAttribute(UnmanagedType.LPArray,ArraySubType = UnmanagedType.Struct,SizeConst = 8,SizeParamIndex = 0)]
程序[] p45_cldxed;
}
解决方案
我相信,code将如下:
[StructLayout(LayoutKind.Sequential,字符集= CharSet.Ansi)
结构p45_cldxed24
{
[的MarshalAs(UnmanagedType.ByValArray,SizeConst = 8)]
程序[] p45_cldxed;
}
这里的关键是,的MarshalAs
属性。
Possible Duplicate:
Marshaling c structures in c#
Actual C structures:
typedef struct procedure
{
char code[8];
}procedure;
typedef struct p45_cldxed24
{
procedure p45_cldxed[8];
}p45_cldxed24;
What would be the equivalent C# structure for p45_cldxed24? Specifically, how would you marshal the array?
Is this correct?
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct p45_cldxed24
{
[MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct,SizeConst = 8,SizeParamIndex=0)]
procedure[] p45_cldxed;
}
解决方案
I believe the code would be as follows:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct p45_cldxed24
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
procedure[] p45_cldxed;
}
The key here is that MarshalAs
attribute.
这篇关于编组C数组在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文