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. Cannot take the address or size of a variable of a managed type

Cannot take the address or size of a variable of a managed type

Scheduled Pinned Locked Moved C#
help
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
    Vikas Salvi
    wrote on last edited by
    #1

    hi all, following is a structure that i hv define [StructLayout(LayoutKind.Sequential, Size = 16)] public struct MESSAGE_INFO { public UInt16 _MessageCode; public UInt16 _ChannelNo; [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)] public UInt16[] _Parameter; } Now when i declare pointer to this structure, It throws the error "Cannot take the address or size of a variable of a managed type" MESSAGE_INFO* ptrMsgInfo But if i declare "public UInt16[] _Parameter" as only "public UInt16 _Parameter" then it compiles perfectly. Any light on this would be highly appreciated... Thanx in advance

    Vikas Salvi Programmer Analyst

    T 1 Reply Last reply
    0
    • V Vikas Salvi

      hi all, following is a structure that i hv define [StructLayout(LayoutKind.Sequential, Size = 16)] public struct MESSAGE_INFO { public UInt16 _MessageCode; public UInt16 _ChannelNo; [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)] public UInt16[] _Parameter; } Now when i declare pointer to this structure, It throws the error "Cannot take the address or size of a variable of a managed type" MESSAGE_INFO* ptrMsgInfo But if i declare "public UInt16[] _Parameter" as only "public UInt16 _Parameter" then it compiles perfectly. Any light on this would be highly appreciated... Thanx in advance

      Vikas Salvi Programmer Analyst

      T Offline
      T Offline
      TJoe
      wrote on last edited by
      #2

      Hello Vikas, MSDN[^] says (at the top of the page) that the pointer can point to "Any user-defined struct type that contains fields of unmanaged types only". When you define the field as an array, then it's considered a managed type. When you define it as just a UInt16, then it's considered an unmanaged type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool).

      Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.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