mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 16:35:49 +00:00
[MSPORTS]
Implement device removal. svn path=/trunk/; revision=53697
This commit is contained in:
parent
3b374be2f7
commit
5fe2e119f5
1 changed files with 67 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue