Conversion of C/C++ Struct To C#.Net CF WinCE

可紊 提交于 2019-12-31 05:00:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!