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. Marshal.Copy for ushort[]?!

Marshal.Copy for ushort[]?!

Scheduled Pinned Locked Moved C#
data-structuresquestioncareer
1 Posts 1 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.
  • D Offline
    D Offline
    Daniel Strigl
    wrote on last edited by
    #1

    I would need a function to copy unsigned short values from a IntPtr to a ushort[]-array, but the Marshal.Copy-function only support the short[]-array! At the moment I do it the following way: ... IntPtr pResult; int len; // this function is located in a DLL CanIpuExecCmd(mid, hid, did, data, data.Length, out pResult, out len); short[] tmp = new short[len]; Marshal.Copy(pResult, tmp, 0, len); Marshal.FreeHGlobal(pResult); ushort[] result = new ushort[tmp.Length]; System.Buffer.BlockCopy(tmp, 0, result, 0, len * 2); return result; Is there no nicer way to do it?

    Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)

    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