Search code examples
c++winapiprint-spooler-api

How to get printer category(type)?


I'm trying to get printer category such as "Fax", or "Printer" which I can see in printer property window.

All I found is that I can get it from DRIVER_INFO_8,

DWORD dwNeeded;
LPBYTE lpDriverInfo;
DWORD dwReturned;
DRIVER_INFO_8 *pInfo;
DWORD i;

EnumPrinterDrivers(NULL,
    NULL,
    8,
    NULL,
    0,
    &dwNeeded,
    &dwReturned);

lpDriverInfo = new BYTE[dwNeeded];
if (lpDriverInfo == NULL) {
    return NULL;
}

EnumPrinterDrivers(NULL,
    NULL,
    8,
    lpDriverInfo,
    dwNeeded,
    &dwNeeded,
    &dwReturned);

pInfo = (DRIVER_INFO_8 *)lpDriverInfo;

but pInfo->dwDriverAttribute doesnt show PRINTER_DRIVER_CATEGORY_FAX, there is on

    cVersion    3   unsigned long
    pName   0x0000000000496994 L"Microsoft Shared Fax Driver"   wchar_t *
    pEnvironment    0x000000000049697c L"Windows x64"   wchar_t *
    pDriverPath 0x0000000000496916 L"C:\\Windows\\system32\\spool\\DRIVERS\\x64\\3\\FXSDRV.DLL" wchar_t *
    pDataFile   0x00000000004968b2 L"C:\\Windows\\system32\\spool\\DRIVERS\\x64\\3\\FXSUI.DLL"  wchar_t *
    pConfigFile 0x000000000049684e L"C:\\Windows\\system32\\spool\\DRIVERS\\x64\\3\\FXSUI.DLL"  wchar_t *
    pHelpFile   0x0000000000000000 <NULL>   wchar_t *
    pDependentFiles 0x0000000000496574 L"C:\\Windows\\system32\\spool\\DRIVERS\\x64\\3\\FXSWZRD.DLL"    wchar_t *
    pMonitorName    0x0000000000000000 <NULL>   wchar_t *
    pDefaultDataType    0x0000000000000000 <NULL>   wchar_t *
    pszzPreviousNames   0x0000000000000000 <NULL>   wchar_t *
    ftDriverDate    {dwLowDateTime=2743894016 dwHighDateTime=29791429 } _FILETIME
    dwlDriverVersion    1688854653387882    unsigned __int64
    pszMfgName  0x000000000049683a L"Microsoft" wchar_t *
    pszOEMUrl   0x0000000000000000 <NULL>   wchar_t *
    pszHardwareID   0x0000000000496808 L"microsoftmicrosoft_s7d14"  wchar_t *
    pszProvider 0x00000000004967f4 L"Microsoft" wchar_t *
    pszPrintProcessor   0x00000000004967e2 L"winprint"  wchar_t *
    pszVendorSetup  0x0000000000000000 <NULL>   wchar_t *
    pszzColorProfiles   0x0000000000000000 <NULL>   wchar_t *
    pszInfPath  0x0000000000496712 L"C:\\Windows\\System32\\DriverStore\\FileRepository\\prnms002.inf_amd64_neutral_d834e48846616289\\prnms002.inf" wchar_t *
    dwPrinterDriverAttributes   1   unsigned long
    pszzCoreDriverDependencies  0x0000000000000000 <NULL>   wchar_t *
    ftMinInboxDriverVerDate {dwLowDateTime=0 dwHighDateTime=0 } _FILETIME
    dwlMinInboxDriverVerVersion 0   unsigned __int64

So I'm a bit confused - how can I get printer type?


Solution

  • To get the PRINTER_DRIVER_CATEGORY_FAX flag, you need at least windows 8 or windows server 2012 (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162507(v=vs.85).aspx).

    Try to use EnumPrinters with PRINTER_INFO_2 instead. You can then test for PRINTER_ATTRIBUTE_FAX