From: Eric Kohl Date: Tue, 13 Sep 2011 09:30:22 +0000 (+0000) Subject: [MSPORTS] X-Git-Tag: backups/icu4ros-bringup@60647~298 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=5fe2e119f5e232a8d07eebf3a785fd5ee4e8c0fd [MSPORTS] Implement device removal. svn path=/trunk/; revision=53697 --- diff --git a/reactos/dll/win32/msports/classinst.c b/reactos/dll/win32/msports/classinst.c index 1d8933c369e..0919a7b3043 100644 --- a/reactos/dll/win32/msports/classinst.c +++ b/reactos/dll/win32/msports/classinst.c @@ -666,6 +666,70 @@ InstallPort(IN HDEVINFO DeviceInfoSet, } +static DWORD +RemovePort(IN HDEVINFO DeviceInfoSet, + IN PSP_DEVINFO_DATA DeviceInfoData) +{ + PORT_TYPE PortType; + HCOMDB hComDB = HCOMDB_INVALID_HANDLE_VALUE; + HKEY hKey; + LONG lError; + DWORD dwPortNumber; + DWORD dwPortNameSize; + WCHAR szPortName[8]; + + /* If we are removing a serial port ... */ + PortType = GetPortType(DeviceInfoSet, DeviceInfoData); + if (PortType == SerialPort) + { + /* Open the port database */ + if (ComDBOpen(&hComDB) == ERROR_SUCCESS) + { + /* Open the device key */ + hKey = SetupDiOpenDevRegKey(DeviceInfoSet, + DeviceInfoData, + DICS_FLAG_GLOBAL, + 0, + DIREG_DEV, + KEY_READ); + if (hKey != INVALID_HANDLE_VALUE) + { + /* Query the port name */ + dwPortNameSize = sizeof(szPortName); + lError = RegQueryValueEx(hKey, + L"PortName", + NULL, + NULL, + (PBYTE)szPortName, + &dwPortNameSize); + + /* Close the device key */ + RegCloseKey(hKey); + + /* If we got a valid port name ...*/ + if (lError == ERROR_SUCCESS) + { + /* Get the port number */ + dwPortNumber = _wtoi(szPortName + wcslen(pszCom)); + + /* Release the port */ + ComDBReleasePort(hComDB, dwPortNumber); + } + } + + /* Close the port database */ + ComDBClose(hComDB); + } + } + + /* Remove the device */ + if (!SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData)) + return GetLastError(); + + return ERROR_SUCCESS; +} + + DWORD WINAPI PortsClassInstaller(IN DI_FUNCTION InstallFunction, @@ -680,6 +744,9 @@ PortsClassInstaller(IN DI_FUNCTION InstallFunction, case DIF_INSTALLDEVICE: return InstallPort(DeviceInfoSet, DeviceInfoData); + case DIF_REMOVE: + return RemovePort(DeviceInfoSet, DeviceInfoData); + default: TRACE("Install function %u ignored\n", InstallFunction); return ERROR_DI_DO_DEFAULT;