https://git.reactos.org/?p=reactos.git;a=commitdiff;h=af37e0e565b581fcb3c750...
commit af37e0e565b581fcb3c750040384b0a48496726a Author: Eric Kohl eric.kohl@reactos.org AuthorDate: Tue Sep 25 17:48:27 2018 +0200 Commit: Eric Kohl eric.kohl@reactos.org CommitDate: Tue Sep 25 17:48:27 2018 +0200
[MSPORTS] Hackfix the code to determine the serial and parallel port numbers.
Now that SetupDiCreateDevRegKeyW is working as expected, we can no longer (ab)use it to retrieve a ports resources. Use SetupDiGetDeviceInstanceIdW instead and open the registry keys manually. --- dll/win32/msports/classinst.c | 127 ++++++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 43 deletions(-)
diff --git a/dll/win32/msports/classinst.c b/dll/win32/msports/classinst.c index 3a261d87e8..255fd3ed71 100644 --- a/dll/win32/msports/classinst.c +++ b/dll/win32/msports/classinst.c @@ -29,6 +29,8 @@ GetBootResourceList(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PCM_RESOURCE_LIST *ppResourceList) { + WCHAR DeviceInstanceIdBuffer[128]; + HKEY hEnumKey = NULL; HKEY hDeviceKey = NULL; HKEY hConfigKey = NULL; LPBYTE lpBuffer = NULL; @@ -36,17 +38,41 @@ GetBootResourceList(HDEVINFO DeviceInfoSet, LONG lError; BOOL ret = FALSE;
+ FIXME("GetBootResourceList()\n"); + *ppResourceList = NULL;
- hDeviceKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, - DeviceInfoData, - DICS_FLAG_GLOBAL, - 0, - DIREG_DEV, - NULL, - NULL); - if (!hDeviceKey) + if (!SetupDiGetDeviceInstanceIdW(DeviceInfoSet, + DeviceInfoData, + DeviceInstanceIdBuffer, + ARRAYSIZE(DeviceInstanceIdBuffer), + &dwDataSize)) + { + ERR("SetupDiGetDeviceInstanceIdW() failed\n"); return FALSE; + } + + lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\CurrentControlSet\Enum", + 0, + KEY_QUERY_VALUE, + &hEnumKey); + if (lError != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW() failed (Error %lu)\n", lError); + goto done; + } + + lError = RegOpenKeyExW(hEnumKey, + DeviceInstanceIdBuffer, + 0, + KEY_QUERY_VALUE, + &hDeviceKey); + if (lError != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW() failed (Error %lu)\n", lError); + goto done; + }
lError = RegOpenKeyExW(hDeviceKey, L"LogConf", @@ -54,7 +80,10 @@ GetBootResourceList(HDEVINFO DeviceInfoSet, KEY_QUERY_VALUE, &hConfigKey); if (lError != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW() failed (Error %lu)\n", lError); goto done; + }
/* Get the configuration data size */ lError = RegQueryValueExW(hConfigKey, @@ -64,12 +93,18 @@ GetBootResourceList(HDEVINFO DeviceInfoSet, NULL, &dwDataSize); if (lError != ERROR_SUCCESS) + { + ERR("RegQueryValueExW() failed (Error %lu)\n", lError); goto done; + }
/* Allocate the buffer */ lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwDataSize); if (lpBuffer == NULL) + { + ERR("Failed to allocate the resource list buffer\n"); goto done; + }
/* Retrieve the configuration data */ lError = RegQueryValueExW(hConfigKey, @@ -79,7 +114,10 @@ GetBootResourceList(HDEVINFO DeviceInfoSet, (LPBYTE)lpBuffer, &dwDataSize); if (lError == ERROR_SUCCESS) + { + ERR("RegQueryValueExW() failed (Error %lu)\n", lError); ret = TRUE; + }
done: if (ret == FALSE && lpBuffer != NULL) @@ -91,6 +129,9 @@ done: if (hDeviceKey) RegCloseKey(hDeviceKey);
+ if (hEnumKey) + RegCloseKey(hEnumKey); + if (ret != FALSE) *ppResourceList = (PCM_RESOURCE_LIST)lpBuffer;
@@ -442,42 +483,42 @@ InstallParallelPort(IN HDEVINFO DeviceInfoSet,
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)); - - /* - * FIXME / HACK: - * This is to get the w2k3 parport.sys to work until we have our own. - * This setting makes the driver accept resources with an IRQ instead - * of only resources without an IRQ. - * - * We should probably also fix IO manager to actually give devices a - * chance to register without an IRQ. CORE-9645 - */ - dwValue = 0; - RegSetValueExW(hKey, - L"FilterResourceMethod", - 0, - REG_DWORD, - (LPBYTE)&dwValue, - sizeof(dwValue)); + /* 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)); + + /* + * FIXME / HACK: + * This is to get the w2k3 parport.sys to work until we have our own. + * This setting makes the driver accept resources with an IRQ instead + * of only resources without an IRQ. + * + * We should probably also fix IO manager to actually give devices a + * chance to register without an IRQ. CORE-9645 + */ + dwValue = 0; + RegSetValueExW(hKey, + L"FilterResourceMethod", + 0, + REG_DWORD, + (LPBYTE)&dwValue, + sizeof(dwValue));
- RegCloseKey(hKey); - } + RegCloseKey(hKey); + } }
/* Install the device */