Hello,
I hope that this is not too far off the mark from the original document but
I am havin serious problems installing a device.
If there is perhaps a better place for this post to be, please let me know.
I am trying to install a network card driver, from an application using
mainly the Setupapi.h install functions.
When I install the device as usuall using device manager, there is no
problem, i deleted all the oem files and it installed using the specified
driver.
When I try and install the device using my application, while viewing the
device manager, it looks like the device is going to install but then it
doesnt and the device appears with an exclamation mark on it.
The device’s properties showed a code 10 (the device failed to start) and
when I looked up setupapi.log, it gave me a great explanation to code
10-“The device failed to start”.
Have a look at the code, all of the functions are successfull and no errors
are returned, but the device does not install!!
bool CTest1Dlg::InstallDriver( LPSTR INFFile, PBOOL RebootRequired)
{
LPSTR HardwareId=“”;
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
GUID ClassGUID;
char ClassName[MAX_CLASS_NAME_LEN];
BOOL ret = TRUE;
int n = GetCurrentDirectory(0,0);
char *InfPath = new char[n+20];
GetCurrentDirectory(n+20,InfPath);
strcat(InfPath, “\”);
strcat(InfPath, INFFile);
// Use the INF File to extract the Class GUID.
if (!SetupDiGetINFClass(InfPath,&ClassGUID,ClassName,sizeof(ClassName),0))
{
m_InstallLog.Insert(GetLastError(),TEXT(“GetINFClass”));
}
// Create the container for the to-be-created Device Information Element.
DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID,0);
if(DeviceInfoSet == INVALID_HANDLE_VALUE)
{
m_InstallLog.Insert(GetLastError(),TEXT(“CreateDeviceInfoList”));
}
// Now create the element.
// Use the Class GUID and Name from the INF file.
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiCreateDeviceInfo(DeviceInfoSet,
ClassName,
&ClassGUID,
NULL,
0,
DICD_GENERATE_ID,
&DeviceInfoData))
{
m_InstallLog.Insert(GetLastError(),TEXT(“CreateDeviceInfo”));
goto cleanup_DeviceInfo;
}
// Add the HardwareID to the Device’s HardwareID property.
if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData,
SPDRP_HARDWAREID,
(LPBYTE)HardwareId,
(lstrlen(HardwareId)+2)*sizeof(TCHAR)))
{
m_InstallLog.Insert(GetLastError(),TEXT(“SetDeviceRegistryProperty”));
ret = FALSE;
goto cleanup_DeviceInfo;
}
// Transform the registry element into an actual devnode
// in the PnP HW tree.
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
DeviceInfoSet,
&DeviceInfoData))
{
m_InstallLog.Format(GetLastError());
ret = FALSE;
goto cleanup_DeviceInfo;
}
// The element is now registered. We must explicitly remove the
// device using DIF_REMOVE, if we encounter any failure from now on.
//
if(!SetupDiSelectDevice(DeviceInfoSet,&DeviceInfoData))
{
if(ERROR_NO_ASSOCIATED_SERVICE==GetLastError())
m_InstallLog.Format(“No associated service”);
}
if(!SetupDiInstallDevice(DeviceInfoSet,&DeviceInfoData))
{
if(ERROR_NO_ASSOCIATED_SERVICE==GetLastError())
m_InstallLog.Format(“No associated service”);
}
//
// Install the Driver.
//
if (!UpdateDriverForPlugAndPlayDevices(0, //top level window handle
HardwareId, //hardwareId of device
InfPath, //path to Inf file
INSTALLFLAG_FORCE, //Install flag
RebootRequired))
{
//remove the device if there is an error
DWORD err = GetLastError();
if (err==ERROR_NO_DRIVER_SELECTED)//(err==ERROR_NO_SUCH_DEVINST)
{
m_InstallLog.Format(“BAD hardwareId or device not plugged in”);
}
//Removes the selected class info for the element
if (!SetupDiCallClassInstaller(
DIF_REMOVE,
DeviceInfoSet,
&DeviceInfoData))
{
m_InstallLog.Insert(GetLastError(),TEXT(“CallClassInstaller(REMOVE)”));
}
}
// Cleanup.
cleanup_DeviceInfo:
int err = GetLastError();
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
SetLastError(err);
return TRUE;
}
I would greatly appreciate if someone could help me with this headwrecker of
a problem.
I just dont know why its not installing the device!!
Thanks in advance!