GetSpoolFileHandle function

The GetSpoolFileHandle function retrieves a handle for the spool file associated with the job currently submitted by the application.

Syntax

HANDLE GetSpoolFileHandle(
  _In_ HANDLE hPrinter
);

Parameters

hPrinter [in]

A handle to the printer to which the job was submitted. This should be the same handle that was used to submit the job. (Use the OpenPrinter or AddPrinter function to retrieve a printer handle.)

Return value

If the function succeeds, it returns a handle to the spool file.

If the function fails, it returns INVALID_HANDLE_VALUE.

Remarks

With the handle to the spool file, your application can write to the spool file with calls to WriteFile followed by CommitSpoolData.

Your application must not call ClosePrinter on hPrinter until after it has accessed the spool file for the last time. Then it should call CloseSpoolFileHandle followed by ClosePrinter. Attempts to access the spool file handle after the original hPrinter has been closed will fail even if the file handle itself has not been closed. CloseSpoolFileHandle will itself fail if ClosePrinter is called first.

This function will fail if it is called before the print job has finished spooling.

Requirements

Requirement Value
Minimum supported client
Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2008 [desktop apps only]
Header
Winspool.h (include Windows.h)
Library
Winspool.lib
DLL
WinSpool.drv
Unicode and ANSI names
GetSpoolFileHandleW (Unicode) and GetSpoolFileHandleA (ANSI)

See also

Printing

Print Spooler API Functions

OpenPrinter

AddPrinter

ClosePrinter

CloseSpoolFileHandle

CommitSpoolData