Click here to Skip to main content
15,891,529 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error message after heavy load Pin
Not Active10-Feb-10 2:59
mentorNot Active10-Feb-10 2:59 
GeneralRe: Error message after heavy load Pin
V.10-Feb-10 3:10
professionalV.10-Feb-10 3:10 
GeneralRe: Error message after heavy load Pin
Rob Philpott10-Feb-10 3:08
Rob Philpott10-Feb-10 3:08 
AnswerRe: Error message after heavy load Pin
Keith Barrow10-Feb-10 2:22
professionalKeith Barrow10-Feb-10 2:22 
GeneralRe: Error message after heavy load Pin
V.10-Feb-10 2:26
professionalV.10-Feb-10 2:26 
AnswerRe: Error message after heavy load Pin
Nish Nishant10-Feb-10 6:42
sitebuilderNish Nishant10-Feb-10 6:42 
GeneralRe: Error message after heavy load Pin
V.10-Feb-10 6:54
professionalV.10-Feb-10 6:54 
QuestionWin32 Printing Status Check Pin
Tiger45610-Feb-10 1:50
Tiger45610-Feb-10 1:50 
I am using below code to check printing status but it always returns 0. It would be great if you can help me . i think there is some problem in the way i am using GetPrinter method

[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        private static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, Int32 pDefault);

        /// <summary>
        /// Close Win32 printer
        /// </summary>
        /// <param name="printer"></param>
        /// <returns></returns>
        [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true,
                                                                    CallingConvention = CallingConvention.StdCall)]
        public static extern bool ClosePrinter(IntPtr printer);



        [DllImport("winspool.Drv", EntryPoint = "GetPrinterDataA", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
        public static extern uint GetPrinterData(
                                                    [In] IntPtr hPrinter,
                                                    [In, MarshalAs(UnmanagedType.LPWStr)] string pValueName,
                                                    [Out, Optional] uint pType,
                                                    [Out, Optional] IntPtr pData,
                                                    uint nSize,
                                                    [Out] uint pcbNeeded
                                                );

        [DllImport("winspool.Drv", EntryPoint = "GetPrinterA", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool GetPrinter(
                                               IntPtr hPrinter,
                                               int dwLevel /* changed type from Int32 */,
                                               IntPtr pPrinter,
                                               int dwBuf /* chagned from Int32*/,
                                               out int dwNeeded /* changed from Int32*/
                                            );
 [StructLayout(LayoutKind.Sequ

ential)]
        internal struct PRINTER_INFO
        {
            public IntPtr pServerName;
            public IntPtr pPrinterName;
            public IntPtr pShareName;
            public IntPtr pPortName;
            public IntPtr pDriverName;
            public IntPtr pComment;
            public IntPtr pLocation;
            public IntPtr pDevMode;
            public IntPtr pSepFile;
            public IntPtr pPrintProcessor;
            public IntPtr pDatatype;
            public IntPtr pParameters;
            public IntPtr pSecurityDescriptor;
            public uint Attributes;
            public uint Priority;
            public uint DefaultPriority;
            public uint StartTime;
            public uint UntilTime;
            public uint Status;
            public uint cJobs;
            public uint AveragePPM;
        }


        [Flags]
        internal enum PrinterStatus : uint
        {
            RS_READY = 0x00000000,   
            PS_PAUSED = 0x00000001,
            PS_ERROR = 0x00000002,
            PS_PENDING_DELETION = 0x00000004,
            PS_PAPER_JAM = 0x00000008,
            PS_PAPER_OUT = 0x00000010,
            PS_MANUAL_FEED = 0x00000020,
            PS_PAPER_PROBLEM = 0x00000040,
            PS_OFFLINE = 0x00000080,
            PS_IO_ACTIVE = 0x00000100,
            PS_BUSY = 0x00000200,
            PS_PRINTING = 0x00000400,
            PS_OUTPUT_BIN_FULL = 0x00000800,
            PS_NOT_AVAILABLE = 0x00001000,
            PS_WAITING = 0x00002000,
            PS_PROCESSING = 0x00004000,
            PS_INITIALIZING = 0x00008000,
            PS_WARMING_UP = 0x00010000,
            PS_TONER_LOW = 0x00020000,
            PS_NO_TONER = 0x00040000,
            PS_PAGE_PUNT = 0x00080000,
            PS_USER_INTERVENTION = 0x00100000,
            PS_OUT_OF_MEMORY = 0x00200000,
            PS_DOOR_OPEN = 0x00400000,
            PS_SERVER_UNKNOWN = 0x00800000,
            PS_POWER_SAVE = 0x01000000
        }


 private PrinterStatus GetPrinterStatus(string printerName)
        {
            PrinterStatus status = PrinterStatus.PS_ERROR;

            PRINTER_INFO printer_info = new PRINTER_INFO();

            Int32 error = 0, written = 0;
            IntPtr hPrn = new IntPtr(0);
            bool success = false;           // Assume failure unless you specifically succeed.
            int needed = 0;

            if (OpenPrinter(printerName, out hPrn, 0))
            {
                GetPrinter(hPrn, 2, IntPtr.Zero, 0, out needed);
                IntPtr ptr = Marshal.AllocHGlobal(needed);

                GetPrinter(hPrn, 2, ptr, needed, out needed);
                printer_info = (PRINTER_INFO)Marshal.PtrToStructure(ptr, typeof(PRINTER_INFO));
                Marshal.FreeHGlobal(ptr);

                ClosePrinter(hPrn);

                status = (PrinterStatus)printer_info.Status;
            }
            else
            {
                status = PrinterStatus.PS_ERROR;
                error = Marshal.GetLastWin32Error();
            }

            return status;
        }


it would to great if you guys can help me to find whats wrong
QuestionHow i can control my web site ? Pin
Nematjon Rahmanov10-Feb-10 1:48
Nematjon Rahmanov10-Feb-10 1:48 
AnswerRe: How i can control my web site ? Pin
Ramkithepower10-Feb-10 2:33
Ramkithepower10-Feb-10 2:33 
AnswerRe: How i can control my web site ? Pin
Nagy Vilmos10-Feb-10 3:09
professionalNagy Vilmos10-Feb-10 3:09 
GeneralRe: How i can control my web site ? Pin
Nematjon Rahmanov10-Feb-10 3:35
Nematjon Rahmanov10-Feb-10 3:35 
QuestionNested Class [modified] Pin
i gr810-Feb-10 1:31
i gr810-Feb-10 1:31 
AnswerRe: Nested Class Pin
OriginalGriff10-Feb-10 1:35
mveOriginalGriff10-Feb-10 1:35 
GeneralRe: Nested Class Pin
i gr810-Feb-10 1:53
i gr810-Feb-10 1:53 
GeneralRe: Nested Class Pin
OriginalGriff10-Feb-10 2:02
mveOriginalGriff10-Feb-10 2:02 
QuestionFile associations and ClickOnce Application Reference files Pin
Baeltazor10-Feb-10 1:13
Baeltazor10-Feb-10 1:13 
AnswerRe: File associations and ClickOnce Application Reference files Pin
Tony Richards10-Feb-10 2:16
Tony Richards10-Feb-10 2:16 
GeneralRe: File associations and ClickOnce Application Reference files Pin
Baeltazor10-Feb-10 3:28
Baeltazor10-Feb-10 3:28 
QuestionXMLNode.SelectSingleNode [modified] Pin
swjam10-Feb-10 0:56
swjam10-Feb-10 0:56 
Questionwhat that means Pin
3bood.ghzawi10-Feb-10 0:55
3bood.ghzawi10-Feb-10 0:55 
AnswerRe: what that means Pin
OriginalGriff10-Feb-10 1:07
mveOriginalGriff10-Feb-10 1:07 
AnswerRe: what that means Pin
V.10-Feb-10 1:14
professionalV.10-Feb-10 1:14 
Questionwhat this means Pin
3bood.ghzawi10-Feb-10 0:51
3bood.ghzawi10-Feb-10 0:51 
AnswerRe: what this means Pin
Calla10-Feb-10 1:23
Calla10-Feb-10 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.