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

SetPrinter (winspool)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("winspool.Drv", EntryPoint="SetPrinterA", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static unsafe extern bool SetPrinter(    IntPtr hPrinter,        // handle to printer object
   uint Level,            // information level
   IntPtr pPrinter,            // printer data buffer
   uint Command        // printer-state command
);

VB Signature:

Declare Function SetPrinter Lib "winspool.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

private void RemoveJobs(String printerName)

    {
        IntPtr hPrinter;
        PRINTER_DEFAULTS defaults = new PRINTER_DEFAULTS
        {
        //PRINTER_ALL_ACCESS
        DesiredAccess = 0x000F000C,
        pDatatype = IntPtr.Zero,
        pDevMode = IntPtr.Zero
        };

        if (OpenPrinter(printerName, out hPrinter, ref defaults) == false)
        {
        int errno = Marshal.GetLastWin32Error();
        throw new Win32Exception(errno);
        }

        if (hPrinter == IntPtr.Zero)
        {
        int errno = Marshal.GetLastWin32Error();
        throw new Win32Exception(errno);
        }

        //3 == PRINTER_CONTROL_PURGE => Removes all Jobs!
        if (SetPrinter(hPrinter, 0, IntPtr.Zero, 3) == false)
        {
        int errno = Marshal.GetLastWin32Error();
        throw new Win32Exception(errno);
        }

        if (ClosePrinter(hPrinter) == false)
        {
        int errno = Marshal.GetLastWin32Error();
        throw new Win32Exception(errno);
        }
    }

Documentation
SetPrinter 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