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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Using Unmanaged C++ Structure in C#

Using Unmanaged C++ Structure in C#

Scheduled Pinned Locked Moved C#
questioncsharpc++data-structurestutorial
2 Posts 2 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.
  • V Offline
    V Offline
    VFaul
    wrote on last edited by
    #1

    How do I convert the following unmanaged C++ structures in C# (which I will be using in PInvoke calls)? typedef struct { unsigned char Camera; unsigned char DecoderId; } VIDEO_SEQ_CMD; typedef struct { int CompressionMode; VIDEO_SEQ_CMD VideoSequence[64]; } USER_CONFIG_DATA; I think the following works for the first struct. I'm not sure how to handle the array in the second struct. [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)] public struct VideoSeqCmd { [FieldOffset(0), MarshalAs(UnmanagedType.U1)] public byte Camera; [FieldOffset(1), MarshalAs(UnmanagedType.U1)] public byte DecoderId; } Thanks!

    A 1 Reply Last reply
    0
    • V VFaul

      How do I convert the following unmanaged C++ structures in C# (which I will be using in PInvoke calls)? typedef struct { unsigned char Camera; unsigned char DecoderId; } VIDEO_SEQ_CMD; typedef struct { int CompressionMode; VIDEO_SEQ_CMD VideoSequence[64]; } USER_CONFIG_DATA; I think the following works for the first struct. I'm not sure how to handle the array in the second struct. [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)] public struct VideoSeqCmd { [FieldOffset(0), MarshalAs(UnmanagedType.U1)] public byte Camera; [FieldOffset(1), MarshalAs(UnmanagedType.U1)] public byte DecoderId; } Thanks!

      A Offline
      A Offline
      aamironline
      wrote on last edited by
      #2

      See this... [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)] public struct UsserConfigData { [FieldOffset(0), MarshalAs(UnmanagedType.I4)] public int CompressionMode; [FieldOffset(1), MarshalAs(UnmanagedType.ByValArray, SizeConst=16, ArraySubType=UnmanagedType.Struct)] VideoSeqCmd [] VideoSequence; }

      M Aamir Maniar aamirOnline.com

      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