问题
Hi I am trying to convert the C/C++ Strcut to C#
C/C++ Struct looks like:
typedef struct _NDISUIO_QUERY_OID
{
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;
My C# Struct is:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct _NDISUIO_QUERY_OID
{
public uint Oid;
[MarshalAs(UnmanagedType.LPWStr)]
public string ptcDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8*sizeof(uint))]
public string Data;
};
I was bit doubtful about the converted structure, can anyone clarify me about this conversion??
If possible can anyone please tell me any tutorials or some references that are useful for conversion of data types or structures from c/c++ to C#.Net CF.
Thanks :)
回答1:
In a previous question of yours, @ctacke said that you won't be able to use MarshalAs(UnmanagedType.LPWStr)
with the compact framework. He asserted that you would have to declare that field as IntPtr
, and marshal it manually.
However, this MSDN document states that MarshalAs(UnmanagedType.LPWStr)
works under the compact framework. I suppose I am inclined to believe the MSDN documents.
The final member is also declared incorrectly. The SizeConst
must be sizeof(uint)
.
来源:https://stackoverflow.com/questions/22560958/conversion-of-c-c-struct-to-c-net-cf-wince