Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. convert C struct into C#.net

convert C struct into C#.net

Scheduled Pinned Locked Moved C#
csharplinuxjsontutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eyeshield21
    wrote on last edited by
    #1

    hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;

    E R 2 Replies Last reply
    0
    • E eyeshield21

      hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Check out the code MS provides for the Windows Mobile Gps, http://msdn.microsoft.com/en-us/library/ms881362.aspx[^] (Sample code comes with the SDK) It contains many C structs written in C#, fairly cool. (Although, the sample like all MS samples doesn't work out of the box)

      Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

      1 Reply Last reply
      0
      • E eyeshield21

        hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        I'm not so hot on all that interop stuff and its a guess, but you could try this:

        [StructLayout(LayoutKind.Sequential)]
        public struct _MT_EVENT
        {
        public long TimeStamp;
        public ulong UserStatus; // Not used by API
        public ulong EventCode; // Event Code
        public ulong SubReason; // Event sub-reason
        public ulong XtraInfo; // Extra information, e.g. termination
        public ulong FuncCode; // Function active when this event occurred
        public ushort Board; // Board ID
        public ushort Channel; // Global Channel ID (GCI)
        public IntPtr ptrBuffer; // Related play/record buffer pointer
        public ulong DataLength; // Byte length of data accessed (played/recorded)
        public IntPtr ptrXtraBuffer; // Pointer to xtra buffer
        public ulong XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer
        public ulong XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer
        public ulong EventFlag; // Falgs of the following:
        }

        Regards, Rob Philpott.

        L 1 Reply Last reply
        0
        • R Rob Philpott

          I'm not so hot on all that interop stuff and its a guess, but you could try this:

          [StructLayout(LayoutKind.Sequential)]
          public struct _MT_EVENT
          {
          public long TimeStamp;
          public ulong UserStatus; // Not used by API
          public ulong EventCode; // Event Code
          public ulong SubReason; // Event sub-reason
          public ulong XtraInfo; // Extra information, e.g. termination
          public ulong FuncCode; // Function active when this event occurred
          public ushort Board; // Board ID
          public ushort Channel; // Global Channel ID (GCI)
          public IntPtr ptrBuffer; // Related play/record buffer pointer
          public ulong DataLength; // Byte length of data accessed (played/recorded)
          public IntPtr ptrXtraBuffer; // Pointer to xtra buffer
          public ulong XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer
          public ulong XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer
          public ulong EventFlag; // Falgs of the following:
          }

          Regards, Rob Philpott.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          size warning: in.NET long/ulong are 64-bit integers, in most other languages when targettingt a 32-bit CPU they just take 32-bit. http://www.pinvoke.net[^] holds lots of useful interop stuff, however it also contains some mistakes, frequently passing a pointer as int (should be IntPtr). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          E 1 Reply Last reply
          0
          • L Luc Pattyn

            size warning: in.NET long/ulong are 64-bit integers, in most other languages when targettingt a 32-bit CPU they just take 32-bit. http://www.pinvoke.net[^] holds lots of useful interop stuff, however it also contains some mistakes, frequently passing a pointer as int (should be IntPtr). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            That is the primary reason I encourage (require) programmers on my teams not to use int and long in C# and instead require Int32 and Int64. The same issue comes up a lot in database programming. I am absolutely sick and tired of seeing cast errors in code because a programmer doesn't know what type they are using.

            Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

            E 1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              That is the primary reason I encourage (require) programmers on my teams not to use int and long in C# and instead require Int32 and Int64. The same issue comes up a lot in database programming. I am absolutely sick and tired of seeing cast errors in code because a programmer doesn't know what type they are using.

              Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

              E Offline
              E Offline
              eyeshield21
              wrote on last edited by
              #6

              thanks alot all...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups