When I removed the driver com port programatically, it is removed. But when reinstalled the driver on com port, the com port number is increased?

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

Вопрос

I have created a driver and installed in com port. When I uninstalled the driver, the driver is uninstalled. But when I re-installed the same drivers, the com port number is increased (lie COM1,COM2, ..... COMN). I have used the WinAPI to remove the driver, below is the code.....

HDEVINFO devs = NULL;
devs = SetupDiGetClassDevs(NULL,NULL,0, DIGCF_ALLCLASSES );

DWORD devCount = 0;
SP_DEVINFO_DATA devInfo;
int enumeratingDevices = 1;
/*This line is essential*/
DWORD dwSize, dwPropertyRegDataType;
TCHAR szDesc[MAX_STRING];

ZeroMemory(szDesc, sizeof(TCHAR) * MAX_STRING);
devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
// Loop through the devices
for ( int i=0; SetupDiEnumDeviceInfo( devs , i , &devInfo) ; i++ )
{
//Here put some code to compare the our driver and uninstall the driver
       SetupDiRemoveDevice(devs,&devInfo);
}
//Clean up
SetupDiDestroyDeviceInfoList(devs);

Just I want to when reinstall the driver, used the same com port number, which in uninstalled previously?

Thanks!

Это было полезно?

Решение

replaced the SetupDiRemoveDevice(...,...) method with SetupDiCallClassInstaller(DIF_REMOVE,devs,&devInfo);

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top