mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 16:52:59 +00:00
[MSPORTS]
- Try to read the PortName registry value and get the port number from the name. - Determine the port number for parallel ports the same way we determine the port number for serial ports, except for the use of the com port database. svn path=/trunk/; revision=51935
This commit is contained in:
parent
1a05e28243
commit
00aee505e3
1 changed files with 112 additions and 11 deletions
|
@ -24,6 +24,9 @@ typedef enum _PORT_TYPE
|
||||||
SerialPort
|
SerialPort
|
||||||
} PORT_TYPE;
|
} PORT_TYPE;
|
||||||
|
|
||||||
|
LPWSTR pszCom = L"COM";
|
||||||
|
LPWSTR pszLpt = L"LPT";
|
||||||
|
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
GetBootResourceList(HDEVINFO DeviceInfoSet,
|
GetBootResourceList(HDEVINFO DeviceInfoSet,
|
||||||
|
@ -243,10 +246,12 @@ InstallSerialPort(IN HDEVINFO DeviceInfoSet,
|
||||||
{
|
{
|
||||||
WCHAR szDeviceDescription[256];
|
WCHAR szDeviceDescription[256];
|
||||||
WCHAR szFriendlyName[256];
|
WCHAR szFriendlyName[256];
|
||||||
WCHAR szPortName[5];
|
WCHAR szPortName[8];
|
||||||
DWORD dwPortNumber;
|
DWORD dwPortNumber = 0;
|
||||||
|
DWORD dwSize;
|
||||||
HCOMDB hComDB = HCOMDB_INVALID_HANDLE_VALUE;
|
HCOMDB hComDB = HCOMDB_INVALID_HANDLE_VALUE;
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
|
LONG lError;
|
||||||
|
|
||||||
TRACE("InstallSerialPort(%p, %p)\n",
|
TRACE("InstallSerialPort(%p, %p)\n",
|
||||||
DeviceInfoSet, DeviceInfoData);
|
DeviceInfoSet, DeviceInfoData);
|
||||||
|
@ -254,9 +259,40 @@ InstallSerialPort(IN HDEVINFO DeviceInfoSet,
|
||||||
/* Open the com port database */
|
/* Open the com port database */
|
||||||
ComDBOpen(&hComDB);
|
ComDBOpen(&hComDB);
|
||||||
|
|
||||||
|
/* Try to read the 'PortName' value and determine the port number */
|
||||||
|
hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
|
||||||
|
DeviceInfoData,
|
||||||
|
DICS_FLAG_GLOBAL,
|
||||||
|
0,
|
||||||
|
DIREG_DEV,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (hKey != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
dwSize = sizeof(szPortName);
|
||||||
|
lError = RegQueryValueEx(hKey,
|
||||||
|
L"PortName",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(PBYTE)szPortName,
|
||||||
|
&dwSize);
|
||||||
|
if (lError == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
if (_wcsnicmp(szPortName, pszCom, wcslen(pszCom)) == 0)
|
||||||
|
{
|
||||||
|
dwPortNumber = _wtoi(szPortName + wcslen(pszCom));
|
||||||
|
TRACE("COM port number found: %lu\n", dwPortNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
||||||
/* Determine the port number from its resources ... */
|
/* Determine the port number from its resources ... */
|
||||||
dwPortNumber = GetSerialPortNumber(DeviceInfoSet,
|
if (dwPortNumber == 0)
|
||||||
DeviceInfoData);
|
dwPortNumber = GetSerialPortNumber(DeviceInfoSet,
|
||||||
|
DeviceInfoData);
|
||||||
|
|
||||||
if (dwPortNumber != 0)
|
if (dwPortNumber != 0)
|
||||||
{
|
{
|
||||||
/* ... and claim the port number in the database */
|
/* ... and claim the port number in the database */
|
||||||
|
@ -273,7 +309,7 @@ InstallSerialPort(IN HDEVINFO DeviceInfoSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build the name of the port device */
|
/* Build the name of the port device */
|
||||||
swprintf(szPortName, L"COM%u", dwPortNumber);
|
swprintf(szPortName, L"%s%u", pszCom, dwPortNumber);
|
||||||
|
|
||||||
/* Close the com port database */
|
/* Close the com port database */
|
||||||
if (hComDB != HCOMDB_INVALID_HANDLE_VALUE)
|
if (hComDB != HCOMDB_INVALID_HANDLE_VALUE)
|
||||||
|
@ -346,23 +382,85 @@ InstallParallelPort(IN HDEVINFO DeviceInfoSet,
|
||||||
{
|
{
|
||||||
WCHAR szDeviceDescription[256];
|
WCHAR szDeviceDescription[256];
|
||||||
WCHAR szFriendlyName[256];
|
WCHAR szFriendlyName[256];
|
||||||
WCHAR szPortName[5];
|
WCHAR szPortName[8];
|
||||||
DWORD dwPortNumber;
|
DWORD dwPortNumber = 0;
|
||||||
|
DWORD dwSize;
|
||||||
|
LONG lError;
|
||||||
|
HKEY hKey;
|
||||||
|
|
||||||
TRACE("InstallParallelPort(%p, %p)\n",
|
TRACE("InstallParallelPort(%p, %p)\n",
|
||||||
DeviceInfoSet, DeviceInfoData);
|
DeviceInfoSet, DeviceInfoData);
|
||||||
|
|
||||||
dwPortNumber = GetParallelPortNumber(DeviceInfoSet,
|
/* Try to read the 'PortName' value and determine the port number */
|
||||||
DeviceInfoData);
|
hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
|
||||||
|
DeviceInfoData,
|
||||||
|
DICS_FLAG_GLOBAL,
|
||||||
|
0,
|
||||||
|
DIREG_DEV,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (hKey != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
dwSize = sizeof(szPortName);
|
||||||
|
lError = RegQueryValueEx(hKey,
|
||||||
|
L"PortName",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(PBYTE)szPortName,
|
||||||
|
&dwSize);
|
||||||
|
if (lError == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
if (_wcsnicmp(szPortName, pszLpt, wcslen(pszLpt)) == 0)
|
||||||
|
{
|
||||||
|
dwPortNumber = _wtoi(szPortName + wcslen(pszLpt));
|
||||||
|
TRACE("LPT port number found: %lu\n", dwPortNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ... try to determine the port number from its resources */
|
||||||
|
if (dwPortNumber == 0)
|
||||||
|
dwPortNumber = GetParallelPortNumber(DeviceInfoSet,
|
||||||
|
DeviceInfoData);
|
||||||
|
|
||||||
|
if (dwPortNumber == 0)
|
||||||
|
{
|
||||||
|
/* FIXME */
|
||||||
|
}
|
||||||
|
|
||||||
if (dwPortNumber != 0)
|
if (dwPortNumber != 0)
|
||||||
{
|
{
|
||||||
swprintf(szPortName, L"LPT%u", dwPortNumber);
|
swprintf(szPortName, L"%s%u", pszLpt, dwPortNumber);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wcscpy(szPortName, L"LPTx");
|
wcscpy(szPortName, L"LPTx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dwPortNumber != 0)
|
||||||
|
{
|
||||||
|
/* Set the 'PortName' value */
|
||||||
|
hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
|
||||||
|
DeviceInfoData,
|
||||||
|
DICS_FLAG_GLOBAL,
|
||||||
|
0,
|
||||||
|
DIREG_DEV,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (hKey != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
RegSetValueExW(hKey,
|
||||||
|
L"PortName",
|
||||||
|
0,
|
||||||
|
REG_SZ,
|
||||||
|
(LPBYTE)szPortName,
|
||||||
|
(wcslen(szPortName) + 1) * sizeof(WCHAR));
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Install the device */
|
/* Install the device */
|
||||||
if (!SetupDiInstallDevice(DeviceInfoSet,
|
if (!SetupDiInstallDevice(DeviceInfoSet,
|
||||||
|
@ -371,6 +469,7 @@ InstallParallelPort(IN HDEVINFO DeviceInfoSet,
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the device description... */
|
||||||
if (SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet,
|
if (SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet,
|
||||||
DeviceInfoData,
|
DeviceInfoData,
|
||||||
SPDRP_DEVICEDESC,
|
SPDRP_DEVICEDESC,
|
||||||
|
@ -379,6 +478,7 @@ InstallParallelPort(IN HDEVINFO DeviceInfoSet,
|
||||||
256 * sizeof(WCHAR),
|
256 * sizeof(WCHAR),
|
||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
|
/* ... and use it to build a new friendly name */
|
||||||
swprintf(szFriendlyName,
|
swprintf(szFriendlyName,
|
||||||
L"%s (%s)",
|
L"%s (%s)",
|
||||||
szDeviceDescription,
|
szDeviceDescription,
|
||||||
|
@ -386,8 +486,9 @@ InstallParallelPort(IN HDEVINFO DeviceInfoSet,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* ... or build a generic friendly name */
|
||||||
swprintf(szFriendlyName,
|
swprintf(szFriendlyName,
|
||||||
L"Serial Port (%s)",
|
L"Parallel Port (%s)",
|
||||||
szPortName);
|
szPortName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue