【发布时间】:2014-04-03 10:21:32
【问题描述】:
我已创建驱动程序并安装在 com 端口中。当我卸载驱动程序时,驱动程序被卸载。但是当我重新安装相同的驱动程序时,com端口号增加了(即COM1,COM2,...... COMN)。我已经用WinAPI删除了驱动,下面是代码.....
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);
只是我想在重装驱动的时候,使用相同的com端口号,之前卸载的那个?
谢谢!
【问题讨论】:
-
我将 SetupDiRemoveDevice(...,...) 方法替换为 SetupDiCallClassInstaller(DIF_REMOVE,devs,&devInfo);现在它工作正常:)
标签: c++ windows winapi device device-driver