locked
Translate C++ Structure to C# equivalent RRS feed

  • Question

  • I need help in translating the following structure to C# equivalent. Can someone help please?

     

    Code Snippet

    typedef struct _WF_VERSIONEX_INFOW
    {
        DWORD dwVersionSize;
        DWORD dwMajorVersion;
        DWORD dwMinorVersion;
        DWORD dwBuildNumber;
        DWORD dwPlatformId;
        WCHAR szCSDVersion[128];
    } WF_VERSIONEX_INFOW, * PWF_VERSIONEX_INFOW;

     

    Code Snippet

    typedef struct _WF_SESSION_TIME
    {
        LARGE_INTEGER ConnectTime;
        LARGE_INTEGER DisconnectTime;
        LARGE_INTEGER LastInputTime;
        LARGE_INTEGER LogonTime;
        LARGE_INTEGER CurrentTime;
    } WF_SESSION_TIME, *PWF_SESSION_TIME;

     

    Code Snippet

    typedef struct _WF_DRIVES
    {
        DWORD DriveLetter; // in ASCII format, i.e. 'C'
        DWORD Flags;       // see below for flag values
    } WF_DRIVES, * PWF_DRIVES;

     

    typedef struct _WF_CLIENT_DRIVES
    {
        DWORD fAutoClientDrives : 1; // are client drives auto-connected?
        DWORD Count;                 // number of actual client drives
        WF_DRIVES Drives[26];        // client drives (room for 26 letters)
    } WF_CLIENT_DRIVES, * PWF_CLIENT_DRIVES;

     

    Thanks in advance...
    Monday, August 25, 2008 11:33 AM

Answers

  • Hi Kannan,

    I tried to map those preceding structures in C#, perhaps you can take a look at the following code snippet.


      

       [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode, Pack=4)]

        public struct _WF_VERSIONEX_INFOW

        {

        public UInt32 dwVersionSize;

        public UInt32 dwMajorVersion;

        public UInt32 dwMinorVersion;

        public UInt32 dwBuildNumber;

        public UInt32 dwPlatformId;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]

        public string szCSDVersion;

        }

     

     

        [StructLayout(LayoutKind.Sequential)]

        public struct LARGE_INTEGER

        {

            public UInt32 LowPart;

            public UInt32 HighPart;

        }

     

        [StructLayout(LayoutKind.Sequential)]

        public class _WF_SESSION_TIME

        {

           public LARGE_INTEGER ConnectTime;

           public LARGE_INTEGER DisconnectTime;

           public LARGE_INTEGER LastInputTime;

           public LARGE_INTEGER LogonTime;

           public LARGE_INTEGER CurrentTime;

        }

     

     

        [StructLayout(LayoutKind.Sequential)]

        public struct _WF_DRIVES

        {

            public UInt32 DriveLetter;

            public UInt32 Flags; 

        }

     

        [StructLayout(LayoutKind.Sequential)]

        public struct _WF_CLIENT_DRIVES

        {

              public UInt32 fAutoClientDrives;

              public UInt32 Count;       

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]

             public  _WF_DRIVES[] Drives;       

        }


    Regards,

    Xun

    Thursday, August 28, 2008 3:45 AM
  • Don't forget to add the reference to the Runtime.InteropServices namespace.

    Thursday, August 28, 2008 8:13 AM

All replies

  • Hi Kannan,

    I tried to map those preceding structures in C#, perhaps you can take a look at the following code snippet.


      

       [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode, Pack=4)]

        public struct _WF_VERSIONEX_INFOW

        {

        public UInt32 dwVersionSize;

        public UInt32 dwMajorVersion;

        public UInt32 dwMinorVersion;

        public UInt32 dwBuildNumber;

        public UInt32 dwPlatformId;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]

        public string szCSDVersion;

        }

     

     

        [StructLayout(LayoutKind.Sequential)]

        public struct LARGE_INTEGER

        {

            public UInt32 LowPart;

            public UInt32 HighPart;

        }

     

        [StructLayout(LayoutKind.Sequential)]

        public class _WF_SESSION_TIME

        {

           public LARGE_INTEGER ConnectTime;

           public LARGE_INTEGER DisconnectTime;

           public LARGE_INTEGER LastInputTime;

           public LARGE_INTEGER LogonTime;

           public LARGE_INTEGER CurrentTime;

        }

     

     

        [StructLayout(LayoutKind.Sequential)]

        public struct _WF_DRIVES

        {

            public UInt32 DriveLetter;

            public UInt32 Flags; 

        }

     

        [StructLayout(LayoutKind.Sequential)]

        public struct _WF_CLIENT_DRIVES

        {

              public UInt32 fAutoClientDrives;

              public UInt32 Count;       

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]

             public  _WF_DRIVES[] Drives;       

        }


    Regards,

    Xun

    Thursday, August 28, 2008 3:45 AM
  • Don't forget to add the reference to the Runtime.InteropServices namespace.

    Thursday, August 28, 2008 8:13 AM