using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Drawing.Printing;
using System.Security.Permissions;
using System.Runtime.InteropServices;
namespace qPrintComponent
{
public static class qStatic
{
private static TimeSpan span1 = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
internal static int hourdiv = span1.Hours * 60;
[SecurityCritical, SecurityTreatAsSafe, PrintingPermission(SecurityAction.Demand, Level = PrintingPermissionLevel.DefaultPrinting)]
public static string GetDefaultPrinter()
{
string defaultprinter;
int num1;
GetDefaultPrinterW(null, out num1);
defaultprinter = new string(' ', num1);
if (GetDefaultPrinterW(defaultprinter, out num1))
defaultprinter = defaultprinter.TrimEnd('\0');
return defaultprinter;
}
[DllImport("winspool.drv", EntryPoint = "OpenPrinterW", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool OpenPrinter(string PrinterName, out IntPtr PrinterHandle, ref qPrinterDefaults PrinterDefaults);
[DllImport("winspool.drv", EntryPoint = "OpenPrinterW", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool OpenPrinter(string PrinterName, out IntPtr PrinterHandle, int PrinterDefaults);
[DllImport("winspool.Drv", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", EntryPoint = "GetDefaultPrinterW", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetDefaultPrinterW(string PrinterName, out int dwNeeded);
[DllImport("winspool.drv", EntryPoint = "SetDefaultPrinter", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetDefaultprinter(string Printername);
[DllImport("winspool.drv", EntryPoint = "GetPrinterW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetPrinter(IntPtr hPrinter, int Level, IntPtr pPrinter, int cbBuf, out int dwNeeded);
[DllImport("winspool.drv", EntryPoint = "SetPrinterW", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetPrinter(IntPtr hPrinter, int Level, IntPtr pPrinter, [In, MarshalAs(UnmanagedType.U4)] PrinterControl Command);
[DllImport("winspool.drv", EntryPoint = "GetPrinterDriverW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetPrinterDriver(IntPtr PrinterHandle, IntPtr pEnvironment, int Level, IntPtr pPrinter, int cbBuf, out int dwNeeded);
[DllImport("winspool.drv", EntryPoint = "EnumPrinterDriversW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool EnumPrinterDrivers([In] string ServerName, [In] string Environmentname, [In] int Level, [Out] IntPtr pdrivers, [In] int cbBuf, out int pcbNeeded, out int pcbReturned);
[DllImport("winspool.drv", EntryPoint = "DeviceCapabilitiesW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern int DeviceCapabilitiesW(string sDevice, string Port, int fwCapability, IntPtr Output, IntPtr device);
[DllImport("winspool.drv", EntryPoint = "FindFirstPrinterChangeNotification", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr FindFirstPrinterChangeNotification(qSafePrinterHandle hPrinter, uint fdwFlags, System.UInt32 fdwOptions, [MarshalAs(UnmanagedType.LPStruct)] qPrinterNotifyOptions pPrinterNotifyOptions);
[DllImport("winspool.drv", EntryPoint = "FindNextPrinterChangeNotification", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern Int32 FindNextPrinterChangeNotification(qSafeWaitPrinterHandle hChange, out uint pdwChange, IntPtr PrinterNotifyOptions, ref IntPtr pPrinterNotifyInfo);
[DllImport("winspool.drv", EntryPoint = "FindNextPrinterChangeNotification", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern Int32 FindNextPrinterChangeNotification(qSafeWaitPrinterHandle hChange, out uint pdwChange, qPrinterNotifyOptions PrinterNotifyOptions, ref IntPtr pPrinterNotifyInfo);
[DllImport("winspool.drv", EntryPoint = "FindClosePrinterChangeNotification", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool FindClosePrinterChangeNotification(System.IntPtr hChange);
[DllImport("winspool.drv", EntryPoint = "FreePrinterNotifyInfo", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern System.Int32 FreePrinterNotifyInfo(IntPtr pPrinterNotifyInfo);
}
}