Hi everybody,
my problem is: OpenPrinter2W(..., PRINTER_OPTION_NO_CACHE) fails with ERROR_NOT_SUPPORTED.
openprinter2 ("The printer data returned by OpenPrinter2 is retrieved from a local cache unless the PRINTER_OPTION_NO_CACHE flag is set in the dwFlags field of the PRINTER_OPTIONS structure referenced by pOptions.", "Accordingly, when opening a local printer, OpenPrinter2 provides no advantage over OpenPrinter.")
along with
printer-option-flags ("PRINTER_OPTION_NO_CACHE: The handle is not cached. All functions applied to a handle returned by OpenPrinter2 will go to the remote computer.")
seem to indicate that calling OpenPrinter2W(..., PRINTER_OPTION_NO_CACHE) is the correct way to obtain the required printer handle hPrinterNoCache, which to use in GetPrinterData( hPrinterNoCache, ... ) on print client computer (computer, which takes share of a printer shared by an other computer in network), so that Windows Print Subsystem would call pfnGetPrinterDataFromPort in my own Language Monitor (for bidirectional communication) on print server (computer, to which the printer is physically connected by cable, and which shares it to other computers in a network). But unfortunately, OpenPrinter2W fails with ERROR_NOT_SUPPORTED, no matter which input parameters I use in OpenPrinter2W. How to obtain hPrinterNoCache ?
C++ code snipplet:
PRINTER_DEFAULTS pdfPrinterDefaults = { NULL, NULL, PRINTER_ALL_ACCESS };
DWORD dwLastError;
HANDLE hPrinterNoCache;
PRINTER_OPTIONS poPrinterOptions;
poPrinterOptions.cbSize = sizeof( PRINTER_OPTIONS );
poPrinterOptions.dwFlags = PRINTER_OPTION_NO_CACHE;
if ( !OpenPrinter2W( L"\\PrintServerName\PrinterName", &hPrinterNoCache, NULL, &poPrinterOptions ) )
// nor does "PrintServerName\PrinterName" work, nor any local printer, nor L"PrintServerName\,XcvMonitor Standard TCP/IP Port", nor using &pdfPrinterDefaults, nor running application on elevated rights, ...
{
dwLastError = GetLastError(); // ERROR_NOT_SUPPORTED
}
Calling OpenPrinter instead of OpenPrinter2 in same spot works without problem.
Dependency Walker shows that Winspool.drv and Spoolss.dll both export OpenPrinter2W, but Win32spl.dll and localspl.dll do not (referring to illustration in introduction-to-print-providers).
Any help is greatly appreciated !
Thanks in advance,
Gebhard