Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

OpenPrinter (winspool)
 
.
Summary
Opens a printer handle given the printer name

C# Signature:

[DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, PRINTER_DEFAULTS pDefault);

It seems to me that the last parameter should be ref PRINTER_DEFAULTS pDefault.

VB Signature:

User-Defined Types:

PRINTER_DEFAULTS

Notes:

As always, only do SetLastError=true if you actually intend to call GetLastError.

ClosePrinter

Tips & Tricks:

Sample Code:

How to cancel a print job:

IntPtr pHandle;
PRINTER_DEFAULTS defaults = new PRINTER_DEFAULTS();
byte b = 0;
OpenPrinter(printerName, out pHandle, defaults);
SetJobA(pHandle, (int)jobID, 0, ref b, (int)Job_Control.Cancel);
ClosePrinter(pHandle);

Alternative Managed API:

The System.Management API allows for lots of printer stuff, but doesn't let you delete a print job in Win2K.

Documentation
OpenPrinter on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions