【问题标题】: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?当我以编程方式删除驱动程序 com 端口时,它被删除了。但是在com口重装驱动后,com口号变大了?
【发布时间】: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


【解决方案1】:

将 SetupDiRemoveDevice(...,...) 方法替换为 SetupDiCallClassInstaller(DIF_REMOVE,devs,&devInfo);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多