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

StackOverflow https://stackoverflow.com/questions/11474317

  •  20-06-2021
  •  | 
  •  

質問

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

役に立ちましたか?

解決

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.


EDIT Sep. 17, 2020 It was requested by someone just today (of the edit) to add an example from the INF. It's been 8 years since I had this issue and I no longer work for this team. However, as best as I can recall, and drawing heavily upon the docs for INF Models Section and INF Manufacturers Section, I hope this helps.

Essentially, the class is specified by the Models Section and the model is specified by the Manufacturer Section.

[Manufacturer]
%MfgName%=Standard,NTamd64

[Standard.NTamd64]
%DeviceString%=<class path or GUID>\<device>

[Strings]
MfgName=ACME
DeviceString="Device Type"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top