示例#1
0
        /// <summary>
        /// Get Printer Info
        /// </summary>
        /// <param name="printer"></param>
        /// <returns></returns>
        public PRINTER_INFO_2 GetPrinter(Printer printer)
        {
            IntPtr pHandle;
            PRINTER_INFO_2 Info2 = new PRINTER_INFO_2();
            PRINTER_DEFAULTS defaults = new PRINTER_DEFAULTS();
            OpenPrinter(printer.Name, out pHandle, defaults);
            uint cbNeeded = 0;

            bool bRet = GetPrinter(pHandle, 2, IntPtr.Zero, 0, ref cbNeeded);
            if (cbNeeded > 0)
            {
                IntPtr pAddr = Marshal.AllocHGlobal((int)cbNeeded);
                bRet = GetPrinter(pHandle, 2, pAddr, cbNeeded, ref cbNeeded);
                if (bRet)
                {

                    Info2 = (PRINTER_INFO_2)Marshal.PtrToStructure(pAddr, typeof(PRINTER_INFO_2));
                }
                Marshal.FreeHGlobal(pAddr);

            }

            ClosePrinter(pHandle);
            return Info2;
        }
示例#2
0
 static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, PRINTER_DEFAULTS pDefault);