GetPrinterDriver function
The GetPrinterDriver function retrieves driver data for the specified printer. If the driver is not installed on the local computer, GetPrinterDriver installs it.
Syntax
BOOL GetPrinterDriver(
_In_ HANDLE hPrinter,
_In_ LPTSTR pEnvironment,
_In_ DWORD Level,
_Out_ LPBYTE pDriverInfo,
_In_ DWORD cbBuf,
_Out_ LPDWORD pcbNeeded
);
Parameters
-
hPrinter [in]
-
A handle to the printer for which the driver data should be retrieved. Use the OpenPrinter or AddPrinter function to retrieve a printer handle.
-
pEnvironment [in]
-
A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64). If this parameter is NULL, the current environment of the calling application and client machine (not of the destination application and print server) is used.
-
Level [in]
-
The printer driver structure returned in the pDriverInfo buffer. This parameter can be one of the following values.
Value Meaning - 1
DRIVER_INFO_1 - 2
DRIVER_INFO_2 - 3
DRIVER_INFO_3 - 4
DRIVER_INFO_4 - 5
DRIVER_INFO_5 - 6
DRIVER_INFO_6 - 8
DRIVER_INFO_8 -
pDriverInfo [out]
-
A pointer to a buffer that receives a structure containing information about the driver, as specified by Level. The buffer must be large enough to store the strings pointed to by the structure members.
To determine the required buffer size, call GetPrinterDriver with cbBuf set to zero. GetPrinterDriver fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer required to hold the array of structures and their data.
-
cbBuf [in]
-
The size, in bytes, of the array at which pDriverInfo points.
-
pcbNeeded [out]
-
A pointer to a value that receives the number of bytes copied if the function succeeds or the number of bytes required if cbBuf is too small.
Return value
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero.
For a non-existent driver, the function returns ERROR_UNKNOWN_PRINTER_DRIVER.
Remarks
Note
This is a blocking or synchronous function and might not return immediately. How quickly this function returns depends on run-time factors such as network status, print server configuration, and printer driver implementation factors that are difficult to predict when writing an application. Calling this function from a thread that manages interaction with the user interface could make the application appear to be unresponsive.
The DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, and DRIVER_INFO_6 structures contain the file name or the full path and file name of the printer driver in the pDriverPath member. An application can use the path and file name to load a printer driver by calling the LoadLibrary function and supplying the path and file name as the single argument.
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows 2000 Professional [desktop apps only] |
Minimum supported server |
Windows 2000 Server [desktop apps only] |
Header |
|
Library |
|
DLL |
|
Unicode and ANSI names |
GetPrinterDriverW (Unicode) and GetPrinterDriverA (ANSI) |