UpdateDriverForPlugAndPlayDevices error is telling me I'm *not* doing something that I am

余生长醉 提交于 2019-12-21 21:12:28

问题


I'm working on a means of installing a driver. Because of the multiple platforms on which this must work, I'm shelling-out to both devcon and dpinst to do the work of driver install/update/removal when needed. While testing, I'm having problems with the shelling out to devcon. To isolate, I wrote a small app to do what devcon does in update see here, using the devcon source from the WinDDK for reference. I'm having some problems with UpdateDriverForPlugAndPlayDevices() from Setup API (actually part of Newdev.dll) see here. The source code is here:

#include <iostream>
#include <Windows.h>
#include <newdev.h>

int main(int argc, char** argv) {
    // Go through the same steps as does dev con for this update crap
    char infFile[MAX_PATH];

    if(3 > argc) {
        std::cerr << "an INF and HW ID must be specified" << std::endl;
        return 1;
    }

    DWORD result(GetFullPathName(argv[1], MAX_PATH, infFile, NULL));
    if((result >= MAX_PATH) || (0 == result)) {
        std::cerr << "path is too long for buffer" << std::endl;
        return 1;
    }

    if(GetFileAttributes(infFile) == -1) {
        std::cerr << "file doesn't exist" << std::endl;
        return 1;
}

    BOOL reboot(FALSE);
    if(!UpdateDriverForPlugAndPlayDevices(NULL, argv[2], infFile, INSTALLFLAG_FORCE, &reboot)) {
        std::cerr << "Failed to install the driver.  Code: "
                  << GetLastError()
                  << std::endl;
        return 2;
}

    if(reboot) {
        std::cout << "A reboot is needed to complete driver install"
                  << std::endl;
    }

    return 0;
}

The program fails when UpdateDriverForPlugAndPlayDevices() returns false. This then prints the error code, returned by GetLastError(), so I'd know what went wrong. The error code returned: 259. According to this resource says this is ERROR_NO_MORE_ITEMS. According to the link for UpdateDriverForPlugAndPlayDevices(), this function returns this error code when, "The function found a match for the HardwareId value, but the specified driver was not a better match than the current driver and the caller did not specify the INSTALLFLAG_FORCE flag." You'll notice from my code that I did specify this flag.

I do not know where to go from here. Can someone please identify from this code what it is I'm missing? This just has the "feel" of something simple, but I'm totally missing it.

Thank you, Andy


回答1:


The problem appeared to be not with the code but with the INF file. Interesting that the documentation for the function said that using that flag will force the install but didn't when the INF file didn't "list" any device classes in the models section. This is how I was able to install eventually. I added the correct device class to the models section in the INF.



来源:https://stackoverflow.com/questions/11474317/updatedriverforplugandplaydevices-error-is-telling-me-im-not-doing-something

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!