GlobalSize() private method

private GlobalSize ( SafeGlobalAllocHandle h ) : UIntPtr
h SafeGlobalAllocHandle
return System.UIntPtr
Esempio n. 1
0
        internal static IntPtr CopyHGlobal(IntPtr data)
        {
            IntPtr src    = UnsafeNativeMethods.GlobalLock(data);
            int    size   = UnsafeNativeMethods.GlobalSize(data);
            IntPtr ptr    = Marshal.AllocHGlobal(size);
            IntPtr buffer = UnsafeNativeMethods.GlobalLock(ptr);

            try
            {
                for (int i = 0; i < size; i++)
                {
                    byte val = Marshal.ReadByte(new IntPtr((long)src + i));

                    Marshal.WriteByte(new IntPtr((long)buffer + i), val);
                }
            }
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnLock(buffer);
                }

                if (src != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnLock(src);
                }
            }
            return(ptr);
        }
Esempio n. 2
0
        public static SafeGlobalAllocHandle CopyHGlobal(SafeGlobalAllocHandle data)
        {
            IntPtr  src  = UnsafeNativeMethods.GlobalLock(data);
            UIntPtr size = UnsafeNativeMethods.GlobalSize(data);
            SafeGlobalAllocHandle ptr = UnsafeNativeMethods.GlobalAlloc(0, size);
            IntPtr buffer             = UnsafeNativeMethods.GlobalLock(ptr);

            try
            {
                UnsafeNativeMethods.MoveMemory(buffer, src, size);
            }
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(ptr);
                }

                if (src != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalUnlock(data);
                }
            }

            return(ptr);
        }