Re: Win AP question
From: Kevin (anonymous_at_discussions.microsoft.com)
Date: 04/16/04
- Next message: Andreas Håkansson: "Re: Any good reason for NOT using interface?"
- Previous message: Marius Horak: "Re: Any good reason for NOT using interface?"
- In reply to: Tom Shelton: "Re: Win AP question"
- Next in thread: BMermuys: "Re: Win AP question"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 16 Apr 2004 04:51:02 -0700
OK Tom this is my code so far
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace SlyPrintMon
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class Form1 : System.Windows.Forms.Form
{
//Declare all Constants here
public const short CCHDEVICENAME = 32;
public const short CCHFORMNAME = 32;
//end of constant declarations
//Declare all structs here
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct PRINTER_DEFAULTS
{
string pDatatype;
DEVMODE pDevMode;
int DesiredAccess;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct DEVMODE
{
string dmDeviceName; // * CCHDEVICENAME;
short dmSpecVersion;
short dmDriverVersion;
short dmSize;
short dmDriverExtra ;
int dmFields;
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
string dmFormName; // * CCHFORMNAME;
short dmUnusedPadding;
int dmBitsPerPel;
int dmPelsWidth;
int dmPelsHeight;
int dmDisplayFlags;
int dmDisplayFrequency;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct JOB_INFO_1
{
public int JobId;
public string pPrinterName;
public string pMachineName;
public string pUserName;
public string pDocument;
public string pDatatype;
public string pStatus;
public int Status;
public int Priority;
public int Position;
public int TotalPages;
public int PagesPrinted;
public SYSTEMTIME Submitted;
}
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
//end of struct declarations
private System.ComponentModel.IContainer components;
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
public static extern int OpenPrinter(string pPrinterName, out System.IntPtr phPrinter, PRINTER_DEFAULTS pd);
[DllImport("winspool.drv")]
public static extern int ClosePrinter(int hPrinter);
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
public static extern int EnumJobs(int hPrinter,int FirstJob,int NoJobs,int Level,ref JOB_INFO_1 jInfo,int cdBuf,out int pcbNeeded,out int pcReturned );
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
System.IntPtr hPrinter;
int lNeeded =0 ;
int lReturned = 0 ;
PRINTER_DEFAULTS pDef = new PRINTER_DEFAULTS();
OpenPrinter("OPTRAE",out hPrinter,pDef);
JOB_INFO_1 jInfo = new JOB_INFO_1();
EnumJobs((int)hPrinter,0,99,1,ref jInfo,0,out lNeeded, out lReturned);
if (lNeeded>0)
{
EnumJobs((int)hPrinter,0,99,1,ref jInfo, lNeeded, out lNeeded,out lReturned);
Console.WriteLine(jInfo.pUserName + " : " + jInfo.TotalPages);
}
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 357);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Now when I run it I can't even get it to give me a handle to the printer:( the hPrinter variable just stays at 0
Any suggestions?
Kevin
- Next message: Andreas Håkansson: "Re: Any good reason for NOT using interface?"
- Previous message: Marius Horak: "Re: Any good reason for NOT using interface?"
- In reply to: Tom Shelton: "Re: Win AP question"
- Next in thread: BMermuys: "Re: Win AP question"
- Messages sorted by: [ date ] [ thread ]