Microsoft.VisualStudio.Project.UnsafeNativeMethods.GlobalAlloc C# (CSharp) Method

GlobalAlloc() private method

private GlobalAlloc ( GlobalAllocFlags flags, UIntPtr size ) : SafeGlobalAllocHandle
flags GlobalAllocFlags
size System.UIntPtr
return SafeGlobalAllocHandle
        internal static extern SafeGlobalAllocHandle GlobalAlloc(GlobalAllocFlags flags, UIntPtr size);

Usage Example

Esempio n. 1
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);
        }