mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[MSPORTS] When the LPT port number gets changed, update the PortName and FriendlyName values in the registry.
This commit is contained in:
parent
52ccfcf6fe
commit
c603c54ab0
1 changed files with 92 additions and 2 deletions
|
@ -159,6 +159,89 @@ ReadPortSettings(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
DWORD
|
||||||
|
ChangePortNumber(
|
||||||
|
_In_ PPORT_DATA pPortData,
|
||||||
|
_In_ DWORD dwNewPortNumber)
|
||||||
|
{
|
||||||
|
WCHAR szDeviceDescription[256];
|
||||||
|
WCHAR szFriendlyName[256];
|
||||||
|
WCHAR szNewPortName[16];
|
||||||
|
HKEY hDeviceKey = INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dwError;
|
||||||
|
|
||||||
|
/* We are done if old and new port number are the same */
|
||||||
|
if (pPortData->dwPortNumber == dwNewPortNumber)
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
|
||||||
|
/* Build the new port name */
|
||||||
|
swprintf(szNewPortName, L"LPT%lu", dwNewPortNumber);
|
||||||
|
|
||||||
|
/* Open the devices hardware key */
|
||||||
|
hDeviceKey = SetupDiOpenDevRegKey(pPortData->DeviceInfoSet,
|
||||||
|
pPortData->DeviceInfoData,
|
||||||
|
DICS_FLAG_GLOBAL,
|
||||||
|
0,
|
||||||
|
DIREG_DEV,
|
||||||
|
KEY_READ | KEY_WRITE);
|
||||||
|
if (hDeviceKey == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
return GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the new 'PortName' value */
|
||||||
|
dwError = RegSetValueExW(hDeviceKey,
|
||||||
|
L"PortName",
|
||||||
|
0,
|
||||||
|
REG_SZ,
|
||||||
|
(LPBYTE)szNewPortName,
|
||||||
|
(wcslen(szNewPortName) + 1) * sizeof(WCHAR));
|
||||||
|
if (dwError != ERROR_SUCCESS)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
/* Save the new port name and number */
|
||||||
|
wcscpy(pPortData->szPortName, szNewPortName);
|
||||||
|
pPortData->dwPortNumber = dwNewPortNumber;
|
||||||
|
|
||||||
|
/* Get the device description... */
|
||||||
|
if (SetupDiGetDeviceRegistryProperty(pPortData->DeviceInfoSet,
|
||||||
|
pPortData->DeviceInfoData,
|
||||||
|
SPDRP_DEVICEDESC,
|
||||||
|
NULL,
|
||||||
|
(PBYTE)szDeviceDescription,
|
||||||
|
sizeof(szDeviceDescription),
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
/* ... and use it to build a new friendly name */
|
||||||
|
swprintf(szFriendlyName,
|
||||||
|
L"%s (%s)",
|
||||||
|
szDeviceDescription,
|
||||||
|
szNewPortName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* ... or build a generic friendly name */
|
||||||
|
swprintf(szFriendlyName,
|
||||||
|
L"Parallel Port (%s)",
|
||||||
|
szNewPortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the friendly name for the device */
|
||||||
|
SetupDiSetDeviceRegistryProperty(pPortData->DeviceInfoSet,
|
||||||
|
pPortData->DeviceInfoData,
|
||||||
|
SPDRP_FRIENDLYNAME,
|
||||||
|
(PBYTE)szFriendlyName,
|
||||||
|
(wcslen(szFriendlyName) + 1) * sizeof(WCHAR));
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (hDeviceKey != INVALID_HANDLE_VALUE)
|
||||||
|
RegCloseKey(hDeviceKey);
|
||||||
|
|
||||||
|
return dwError;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
VOID
|
VOID
|
||||||
WritePortSettings(
|
WritePortSettings(
|
||||||
|
@ -169,6 +252,7 @@ WritePortSettings(
|
||||||
DWORD dwFilterResourceMethod;
|
DWORD dwFilterResourceMethod;
|
||||||
DWORD dwLegacy;
|
DWORD dwLegacy;
|
||||||
DWORD dwPortNumber;
|
DWORD dwPortNumber;
|
||||||
|
DWORD dwPortMap;
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD dwError;
|
DWORD dwError;
|
||||||
|
|
||||||
|
@ -248,10 +332,16 @@ WritePortSettings(
|
||||||
dwPortNumber++;
|
dwPortNumber++;
|
||||||
if (dwPortNumber != pPortData->dwPortNumber)
|
if (dwPortNumber != pPortData->dwPortNumber)
|
||||||
{
|
{
|
||||||
FIXME("Port name changed! LPT%lu --> LPT%lu", pPortData->dwPortNumber, dwPortNumber);
|
GetUsedPorts(&dwPortMap);
|
||||||
|
|
||||||
|
if (dwPortMap & 1 << dwPortNumber)
|
||||||
|
{
|
||||||
|
ERR("Port LPT%lu is already in use!\n", dwPortNumber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// pPortData->dwPortNumber = dwPortNumber;
|
ChangePortNumber(pPortData,
|
||||||
|
dwPortNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue