的C / C ++结构体转换为C#.NET CF WinCE的转换为、结构、NET、CF

2023-09-03 06:52:52 作者:孤独成瘾

你好我想转换成C / C ++ Strcut到C#

Hi I am trying to convert the C/C++ Strcut to C#

C / 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;

我的C#结构是:

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??

如果可能的任何人都可以告诉我任何教程或一些参考是有用的转换数据类型或结构从C / C ++,以C#.NET CF。

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.

感谢:)

推荐答案

在你的一个 previous问题中,@ ctacke说,你将无法使用的MarshalAs(UnmanagedType.LPWStr)与紧凑的框架。他声称,你将不得不宣布该字段为的IntPtr ,并手动名帅它。

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.

不过,这 MSDN文档指出,的MarshalAs(UnmanagedType.LPWStr)和紧凑的框架下。我想,我倾向于相信MSDN文档。

However, this MSDN document states that MarshalAs(UnmanagedType.LPWStr) works under the compact framework. I suppose I am inclined to believe the MSDN documents.

最后的成员也宣告不正确。该 SizeConst 必须的sizeof(UINT)

The final member is also declared incorrectly. The SizeConst must be sizeof(uint).