Marshal.Copy for ushort[]?!
C#
1
Posts
1
Posters
0
Views
1
Watching
-
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. ;)