Author: ekohl
Date: Tue Sep 13 09:30:22 2011
New Revision: 53697
URL:
http://svn.reactos.org/svn/reactos?rev=53697&view=rev
Log:
[MSPORTS]
Implement device removal.
Modified:
trunk/reactos/dll/win32/msports/classinst.c
Modified: trunk/reactos/dll/win32/msports/classinst.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msports/classins…
==============================================================================
--- trunk/reactos/dll/win32/msports/classinst.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msports/classinst.c [iso-8859-1] Tue Sep 13 09:30:22 2011
@@ -666,6 +666,70 @@
}
+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 @@
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;