1

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 :)

arya2arya
  • 291
  • 2
  • 21

1 Answers1

2

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).

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Sir Thanks :) MarshalAs(UnmanagedType.LPWStr) is also supporting :) I have to verify the last parameter, I am Bit doubtful about it !! – arya2arya Mar 21 '14 at 14:13
  • Definitely let us know if it works with MarshalAs for both of those fields. – ctacke Mar 21 '14 at 17:22
  • @ctacke Yes sir it's working.. no exceptions.. MarshalAs(UnmanagedType.LPWStr) is supporting in WIN CE. – arya2arya Mar 24 '14 at 09:03
  • @ctacke Sir Can you please give me a suggestion.. [How to do memcpy in C# .Net CF with the following task](http://stackoverflow.com/questions/22604111/how-to-do-memcpy-in-c-sharp-net-cf-with-the-following-task) – arya2arya Mar 24 '14 at 09:17