How to use DrvDeviceCapabilities in winddiui.h (WITH winspool.lib added but LNK2019 unresolved external symbol STILL occured )

GanDalf LeBron 0 Reputation points
2024-06-06T01:41:05.85+00:00

Function DrvDeviceCapabilities(winddiui.h) should be used if I want to identify a printer's color capability according to this link. But there is always a link error (LNK2019 unresolved external symbol ) though I added winspool.lib to Library Directories in VC++ Directories and Additional Dependencies in Linker-Input.

Image

I used dumpbin tool to find related symbol in ALL lib files but found nothing. As a contrast to DrvDeviceCapabilities, some other symbols can be easily found like OpenPrinter and StartDoc.

Image

It seems that DeviceCapabilitiesA function can also retrieves the capabilities of a printer driver but it isn't be mentioned in this link . What is the difference between these functions or structures? And how to get the printer capabilities in a correct way?

Any replies would be appreciated!

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,764 questions
Windows Driver Kit (WDK)
Windows Driver Kit (WDK)
A set of Microsoft tools that are used to develop, test, and deploy Windows drivers.
126 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. RLWA32 45,701 Reputation points
    2024-06-06T10:05:25.2+00:00

    The DrvDeviceCapabilities function is not exported from winspool.drv but can be obtained as follows -

    Minimal example tested on Win10 22H2

    #include <Windows.h>
    #include <winddiui.h>
    
    #include <stdio.h>
    #include <tchar.h>
    #include <memory>
    
    typedef decltype(DrvDeviceCapabilities)* DDC;
    
    int main()
    {
        HANDLE hPrinter{};
        DWORD cbNeeded{};
        if (OpenPrinter((LPTSTR)_T("Microsoft Print to PDF"), &hPrinter, NULL))
        {
            if (!GetPrinterDriver(hPrinter, NULL, 2, NULL, 0, &cbNeeded) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
            {
                std::unique_ptr<BYTE[]> buf = std::make_unique<BYTE[]>(cbNeeded);
                if (GetPrinterDriver(hPrinter, NULL, 2, buf.get(), cbNeeded, &cbNeeded))
                {
                    PDRIVER_INFO_2 pdrv2 = (PDRIVER_INFO_2) buf.get();
                    _tprintf_s(_T("DLL to load: %s\n"), pdrv2->pConfigFile);
    
                    HMODULE hMod = LoadLibrary(pdrv2->pConfigFile);
                    if (hMod)
                    {
                        DDC pfDrvDeviceCapabilities = (DDC)GetProcAddress(hMod, "DrvDeviceCapabilities");
                        if (pfDrvDeviceCapabilities)
                            _tprintf_s(_T("GetProcAddress succeeeded!\n"));
                        else
                            _tprintf_s(_T("GetProcAddress error ws %d\n"), GetLastError());
    
                        FreeLibrary(hMod);
                    }
                    else
                        _tprintf_s(_T("LoadLibrary error ws %d\n"), GetLastError());
                }
                else
                    _tprintf_s(_T("GetPrinterDriver error was %d\n"), GetLastError());
            }
            else
                _tprintf_s(_T("GetPrinterDriver error was %d\n"), GetLastError());
    
            ClosePrinter(hPrinter);
        }
    
        return 0;
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.