Hi everybody!!
I have device driver (*.inf & *.sys) and when I use ‘Add/Remove Hardware
Wizard applet in Control Panel’ everything is OK!
I have BIG PROBLEM because I have to write my own programme which will
install that device driver to system ( WinXP ).
I do this like this:
LPTSTR INFFile ; //INFFile = “C:\Driver\genport.inf”
LPTSTR HardwareId ; //HardwareID = “root\portio”
HDEVINFO DeviceInfoSet = 0;
SP_DEVINFO_DATA DeviceInfoData;
GUID ClassGUID;
TCHAR ClassName[MAX_CLASS_NAME_LEN];
DWORD err;
//
// Use the INF File to extract the Class GUID.
//
if
(!SetupDiGetINFClass(INFFile,&ClassGUID,ClassName,sizeof(ClassName),0))
{
return DisplayError(TEXT(“GetINFClass”));
}
//
// Create the container for the to-be-created Device Information
Element.
//
DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID,0);
if(DeviceInfoSet == INVALID_HANDLE_VALUE)
{
return DisplayError(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))
{
DisplayError(TEXT(“CreateDeviceInfo”));
goto cleanup_DeviceInfo;
}
//
// Add the HardwareID to the Device’s HardwareID property.
//
if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
&DeviceInfoData,
SPDRP_HARDWAREID,
(LPBYTE)HardwareId,
(lstrlen(HardwareId)+1+1)*sizeof(TCHAR)))
{
DisplayError(TEXT(“SetDeviceRegistryProperty”));
goto cleanup_DeviceInfo;
}
//
// Transform the registry element into an actual devnode
// in the PnP HW tree.
//
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
DeviceInfoSet,
&DeviceInfoData))
{
DisplayError(TEXT(“CallClassInstaller(REGISTERDEVICE)”));
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.
//
//
// Install the Driver.
//
if (!UpdateDriverForPlugAndPlayDevices(0,
HardwareId,
INFFile,
INSTALLFLAG_FORCE,
RebootRequired))
{
DWORD err = GetLastError();
DisplayError(TEXT(“UpdateDriverForPlugAndPlayDevices”));
if (!SetupDiCallClassInstaller(
DIF_REMOVE,
DeviceInfoSet,
&DeviceInfoData))
{
DisplayError(TEXT(“CallClassInstaller(REMOVE)”));
}
SetLastError(err);
}
//
// Cleanup.
//
cleanup_DeviceInfo:
err = GetLastError();
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
SetLastError(err);
return err == NO_ERROR;
The application always shows me error : “SetDeviceRegistryProperty FAILURE
: The parameter is incorrect.”
I don’t know what to do!!
If someone has the good example of installation of driver then whether would
can pass the link for this!
PLEASE HELP !!!
I greet form Poland ( Pozdrawiam wszystkich)!
Megasus