GlobalFree() private method

private GlobalFree ( IntPtr hMem ) : IntPtr
hMem IntPtr
return IntPtr
示例#1
0
            FreeUnmanagedPrintDlgExStruct(
                IntPtr unmanagedBuffer
                )
            {
                if (unmanagedBuffer == IntPtr.Zero)
                {
                    return;
                }

                IntPtr devModeHandle  = IntPtr.Zero;
                IntPtr devNamesHandle = IntPtr.Zero;
                IntPtr pageRangePtr   = IntPtr.Zero;

                //
                // Extract the devmode and devnames handles from the appropriate PRINTDLGEX structure
                //
                if (!Is64Bit())
                {
                    NativeMethods.PRINTDLGEX32 pdex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure(
                        unmanagedBuffer,
                        typeof(NativeMethods.PRINTDLGEX32));
                    devModeHandle  = pdex.hDevMode;
                    devNamesHandle = pdex.hDevNames;
                    pageRangePtr   = pdex.lpPageRanges;
                }
                else
                {
                    NativeMethods.PRINTDLGEX64 pdex = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure(
                        unmanagedBuffer,
                        typeof(NativeMethods.PRINTDLGEX64));
                    devModeHandle  = pdex.hDevMode;
                    devNamesHandle = pdex.hDevNames;
                    pageRangePtr   = pdex.lpPageRanges;
                }

                if (devModeHandle != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(devModeHandle);
                }

                if (devNamesHandle != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(devNamesHandle);
                }

                if (pageRangePtr != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(pageRangePtr);
                }

                Marshal.FreeHGlobal(unmanagedBuffer);
            }
示例#2
0
            private void FreeUnmanagedPrintDlgExStruct(IntPtr unmanagedBuffer)
            {
                if (unmanagedBuffer == IntPtr.Zero)
                {
                    return;
                }
                IntPtr intPtr  = IntPtr.Zero;
                IntPtr intPtr2 = IntPtr.Zero;
                IntPtr intPtr3 = IntPtr.Zero;

                if (!this.Is64Bit())
                {
                    NativeMethods.PRINTDLGEX32 printdlgex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure(unmanagedBuffer, typeof(NativeMethods.PRINTDLGEX32));
                    intPtr  = printdlgex.hDevMode;
                    intPtr2 = printdlgex.hDevNames;
                    intPtr3 = printdlgex.lpPageRanges;
                }
                else
                {
                    NativeMethods.PRINTDLGEX64 printdlgex2 = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure(unmanagedBuffer, typeof(NativeMethods.PRINTDLGEX64));
                    intPtr  = printdlgex2.hDevMode;
                    intPtr2 = printdlgex2.hDevNames;
                    intPtr3 = printdlgex2.lpPageRanges;
                }
                if (intPtr != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(intPtr);
                }
                if (intPtr2 != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(intPtr2);
                }
                if (intPtr3 != IntPtr.Zero)
                {
                    UnsafeNativeMethods.GlobalFree(intPtr3);
                }
                Marshal.FreeHGlobal(unmanagedBuffer);
            }