0
votes

I have a program that installs a USB driver for a specific device and then updates the device firmware. I use SetupCopyOEMInf() for installing the driver, however, this function doesn't seem to be making the driver active unless I restart the system.

I.e. the installation goes OK, SetupCopyOEMInf() returns OK but the device still remains "Unknown" in the Device Manager unless I restart Windows. However, when I install the driver manually, the system recognizes everything fine and the device quickly gets bound to the driver.

Is there anything else apart from SetupCopyOEMInf() I should do so that the driver gets bound to the device?

Thanks.

2
I'm not certain, but I believe this is the expected behaviour: the function installs the driver but does not scan for devices that it is applicable to, and is generally used for installing drivers for devices that are not yet present. Perhaps try DiInstallDriver instead? "The DiInstallDriver function preinstalls a driver in the driver store and then installs the driver on devices present in the system that the driver supports." - Harry Johnston
@HarryJohnston thanks for pointing me in the right direction. DiInstallDriver seems to be an equivalent of SetupCopyOEMInf + UpdateDriverForPlugAndPlayDevices and is limited to 32-bit systems, but works Ok. - mojuba
According to the documentation, at least, none of these functions are limited to 32-bit systems; however, on a 64-bit system, some of them can only be called by a 64-bit application. - Harry Johnston
@HarryJohnston they are limited unfortunately (except for SetupCopyOEMInf) see notes on ERROR_IN_WOW64 for DiInstallDriver - mojuba
ERROR_IN_WOW64 means that you're trying to call the function from a 32-bit application on a 64-bit system. If you use a 64-bit application the problem will go away. - Harry Johnston

2 Answers

1
votes

Try installing your driver using devcon, the source is available in the WDK, using devcon dp_add mydriver.inf. If this works you can step through the source in devcon to find out how to properly install your driver dynamically, devcon also uses SetupCopyOEMInf, so if it works you can compare this to your code to find out what the difference is, here is a snippet in case it helps you now:

TCHAR SourceInfFileName[MAX_PATH]; // Full path name
TCHAR DestinationInfFileName[MAX_PATH];
PTSTR DestinationInfFileNameComponent = NULL;

if (!SetupCopyOEMInf(SourceInfFileName,
                NULL,
                SPOST_PATH,
                0,
                DestinationInfFileName,
                ARRAYSIZE(DestinationInfFileName),
                NULL,
                &DestinationInfFileNameComponent)) {
    // Handle Error
}
0
votes

I think Device Manager restarts the device after a driver update.