Re : Printer Status

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gordon Truslove

    #1

    Re : Printer Status

    I've been trying to get the printer status using GetPrinter and
    Printer_Info_2

    I'm getting closer, but it still fails.

    Error 122 - The data area passed to a system call is too small.

    [StructLayout( LayoutKind.Sequ ential,CharSet= CharSet.Auto)]

    public struct PRINTERINFO2

    {

    [MarshalAs(Unman agedType.LPTStr )]public string pServerName;

    [MarshalAs(Unman agedType.LPTStr )]public string pPrinterName;

    [MarshalAs(Unman agedType.LPTStr )]public string pShareName;

    [MarshalAs(Unman agedType.LPTStr )]public string pPortName;

    [MarshalAs(Unman agedType.LPTStr )]public string pDriverName;

    [MarshalAs(Unman agedType.LPTStr )]public string pComment;

    [MarshalAs(Unman agedType.LPTStr )]public string pLocation;

    public IntPtr pDevMode;

    [MarshalAs(Unman agedType.LPTStr )]public string pSepFile;

    [MarshalAs(Unman agedType.LPTStr )]public string pPrintProcessor ;

    [MarshalAs(Unman agedType.LPTStr )]public string pDatatype;

    [MarshalAs(Unman agedType.LPTStr )]public string pParameters;

    public IntPtr pSecurityDescri ptor;

    public int Attributes;

    public int Priority;

    public int DefaultPriority ;

    public int StartTime;

    public int UntilTime;

    public int Status;

    public int cJobs;

    public int AveragePPM;

    }

    public class Printer

    {

    [ DllImport( "winspool.drv", CharSet=CharSet .Unicode,ExactS pelling=false,

    CallingConventi on=CallingConve ntion.StdCall )]

    public static extern long OpenPrinter(str ing pPrinterName,re f IntPtr
    phPrinter, int pDefault);

    [ DllImport(

    "winspool.drv", CharSet=CharSet .Unicode,ExactS pelling=true,

    CallingConventi on=CallingConve ntion.StdCall )]

    public static extern long ClosePrinter(In tPtr hPrinter);

    [ DllImport(

    "winspool.d rv" ,CharSet=CharSe t.Auto)]

    public static extern bool GetPrinter(IntP tr hPrinter,int Level,ref
    PRINTERINFO2 pPrinter,int cbBuf,ref int pcbNeeded);

    }

    public class App

    {

    public static void Main ()

    {

    System.IntPtr lhPrinter=new System.IntPtr() ;

    Printer.OpenPri nter("Epson EPL-5700",ref lhPrinter,0);

    PRINTERINFO2 PI=new PRINTERINFO2();

    int Need=0;

    Console.WriteLi ne(Printer.GetP rinter(lhPrinte r,2,ref
    PI,Marshal.Size Of(PI),ref Need));


    Console.WriteLi ne("Error "+Marshal.GetLa stWin32Error()) ;


    Printer.ClosePr inter(lhPrinter );

    Console.ReadLin e();

    }

    }


Working...