Reputation: 30132
I have eight different printers installed on a Windows 8.1 computer. These printers are various manufacturers and models, there are two HP LaserJet printers, an Epson inkjet, a CutePDF Writer, a Windows Fax printer, and others.
For all of my printers, this call to DeviceCapabilities returns -1, which means "either that the capability is not supported or there was a general function failure". Other fwCapability
values, like DC_DUPLEX
, succeed.
DeviceCapabilities(pDevice, pPort, DC_MANUFACTURER, NULL, &devMode);
My guess is that DC_MANUFACTURER
and DC_MODEL
are "newer" and therefore unimplemented. CUPS has a printer-make-and-model
attribute, required PPD options Manufacturer
and Model
.
What is the proper way to query the manufacturer and model of a printer with Win32?
Upvotes: 2
Views: 2495
Reputation: 31599
DC_MANUFACTURER
and DC_MODEL
are not listed in MSDN documentation, they are not worth investigating.
pDevice
parameter in DeviceCapabilities
is usually printer name and model. For example "HP LaserJet 123" It's the same thing in control panel. That should be all you need.
Sometimes printer name gets changed, in which case you can use driver name to identify the printer.
int wmain()
{
DWORD flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
int level = 2;
PRINTER_INFO_2* printerInfo;
DWORD memsize, printer_count;
EnumPrinters(flags, NULL, level, NULL, 0, &memsize, &printer_count);
if (memsize < 1) return 0;
BYTE* bytes = new BYTE[memsize];
if (EnumPrinters(flags, NULL, level, bytes, memsize, &memsize, &printer_count))
{
printerInfo = (PRINTER_INFO_2*)bytes;
for (UINT i = 0; i < printer_count; i++)
{
std::wcout << "printer: " << printerInfo->pPrinterName << "\n";
std::wcout << "printerInfo->pDriverName: " << printerInfo->pDriverName << "\n\n";
printerInfo++;
}
}
delete[] bytes;
return 0;
}
In above code, printerInfo->pPrinterName
should match printer name as shown in control panel (or pDevice
). printerInfo->pDriverName
should always be printer name and model.
To get the manufacturer name you can go through DRIVER_INFO_6
and pszMfgName
However that may not be very useful.
Upvotes: 1