Esempio n. 1
0
            private PrintTicket AcquirePrintTicket(IntPtr devModeHandle, string printQueueName)
            {
                PrintTicket result = null;

                byte[] array  = null;
                IntPtr intPtr = IntPtr.Zero;

                try
                {
                    intPtr = UnsafeNativeMethods.GlobalLock(devModeHandle);
                    NativeMethods.DEVMODE devmode = (NativeMethods.DEVMODE)Marshal.PtrToStructure(intPtr, typeof(NativeMethods.DEVMODE));
                    array = new byte[(int)(devmode.dmSize + devmode.dmDriverExtra)];
                    Marshal.Copy(intPtr, array, 0, array.Length);
                }
                finally
                {
                    if (intPtr != IntPtr.Zero)
                    {
                        UnsafeNativeMethods.GlobalUnlock(devModeHandle);
                    }
                }
                SystemDrawingHelper.NewDefaultPrintingPermission().Assert();
                try
                {
                    using (PrintTicketConverter printTicketConverter = new PrintTicketConverter(printQueueName, PrintTicketConverter.MaxPrintSchemaVersion))
                    {
                        result = printTicketConverter.ConvertDevModeToPrintTicket(array);
                    }
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
                return(result);
            }
Esempio n. 2
0
            AcquirePrintTicket(
                IntPtr devModeHandle,
                string printQueueName
                )
            {
                PrintTicket printTicket = null;

                byte[] devModeData = null;

                //
                // Copy the devmode into a byte array
                //
                IntPtr pDevMode = IntPtr.Zero;

                try
                {
                    pDevMode = UnsafeNativeMethods.GlobalLock(devModeHandle);

                    NativeMethods.DEVMODE devMode = (NativeMethods.DEVMODE)Marshal.PtrToStructure(
                        pDevMode,
                        typeof(NativeMethods.DEVMODE));
                    devModeData = new byte[devMode.dmSize + devMode.dmDriverExtra];
                    Marshal.Copy(pDevMode, devModeData, 0, devModeData.Length);
                }
                finally
                {
                    if (pDevMode != IntPtr.Zero)
                    {
                        UnsafeNativeMethods.GlobalUnlock(devModeHandle);
                    }
                }

                SystemDrawingHelper.NewDefaultPrintingPermission().Assert(); //BlessedAssert
                try
                {
                    //
                    // Convert the devmode data to a PrintTicket object
                    //
                    using (PrintTicketConverter ptConverter = new PrintTicketConverter(
                               printQueueName,
                               PrintTicketConverter.MaxPrintSchemaVersion))
                    {
                        printTicket = ptConverter.ConvertDevModeToPrintTicket(devModeData);
                    }
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }

                return(printTicket);
            }
Esempio n. 3
0
            AcquirePrintTicket(
                IntPtr devModeHandle,
                string printQueueName
                )
            {
                PrintTicket printTicket = null;

                byte[] devModeData = null;

                //
                // Copy the devmode into a byte array
                //
                IntPtr pDevMode = IntPtr.Zero;

                try
                {
                    pDevMode = UnsafeNativeMethods.GlobalLock(devModeHandle);

                    NativeMethods.DEVMODE devMode = Marshal.PtrToStructure <NativeMethods.DEVMODE>(pDevMode);
                    devModeData = new byte[devMode.dmSize + devMode.dmDriverExtra];
                    Marshal.Copy(pDevMode, devModeData, 0, devModeData.Length);
                }
                finally
                {
                    if (pDevMode != IntPtr.Zero)
                    {
                        UnsafeNativeMethods.GlobalUnlock(devModeHandle);
                    }
                }

                //
                // Convert the devmode data to a PrintTicket object
                //
                using (PrintTicketConverter ptConverter = new PrintTicketConverter(
                           printQueueName,
                           PrintTicketConverter.MaxPrintSchemaVersion))
                {
                    printTicket = ptConverter.ConvertDevModeToPrintTicket(devModeData);
                }

                return(printTicket);
            }