[英]c# pinvoke marshall struct
I have an unmanaged struct I'd like to marshal to c# that looks basically like this: 我有一个非托管的结构,我想编组到C#,基本上看起来像这样:
struct DateTimeStruct{
double datetimestamp;
};
struct MyStruct{
char firstname[40];
char lastname[40];
DateTimeStruct bday;
unsigned integer bool1;
int val1;
};
What is the the correct c# declaration? 正确的C#声明是什么?
The struct isn't a problem, it will marshal correctly as-is. 该结构不是问题,它将按原样正确封送。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct MyStruct{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40]
string firstname;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40]
string lastname;
DateTimeStruct bday;
uint bool1;
int val1;
}
Of course, it will be up to you to convert the double to a matching DateTime value. 当然,将double转换为匹配的DateTime值取决于您。 How it is encoded is unguessable from your question.
从您的问题来看,如何编码是毫无疑问的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.