From 543acff48039661b7886e24ec4f9bf04a36f76c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 12 Oct 2005 08:14:56 +0000 Subject: [PATCH] Fix SetupDiGetDeviceRegistryPropertyA, which should return the required size and the registry data type if the buffer is too small (typical case when you call it 2 times: 1st time to get the required size, 2nd time to get real data) svn path=/trunk/; revision=18408 --- reactos/lib/setupapi/devinst.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/reactos/lib/setupapi/devinst.c b/reactos/lib/setupapi/devinst.c index a7dfad819ea..22a754ca7d9 100644 --- a/reactos/lib/setupapi/devinst.c +++ b/reactos/lib/setupapi/devinst.c @@ -2157,7 +2157,7 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyA( DWORD PropertyBufferSizeW; PBYTE PropertyBufferW; - TRACE("%04lx %p %ld %p %p %ld %p\n", (DWORD)devinfo, DeviceInfoData, + TRACE("%p %p %ld %p %p %ld %p\n", devinfo, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); @@ -2173,19 +2173,26 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyA( PropertyBufferSizeW, &RequiredSizeW); + if (bResult || GetLastError() == ERROR_MORE_DATA) + { + bIsStringProperty = (RegType == REG_SZ || RegType == REG_MULTI_SZ || RegType == REG_EXPAND_SZ); + + if (bIsStringProperty) + RequiredSizeA = RequiredSizeW / sizeof(WCHAR); + else + RequiredSizeA = RequiredSizeW; + if (RequiredSize) + *RequiredSize = RequiredSizeA; + if (PropertyRegDataType) + *PropertyRegDataType = RegType; + } + if (!bResult) { HeapFree(GetProcessHeap(), 0, PropertyBufferW); return bResult; } - bIsStringProperty = (RegType == REG_SZ || RegType == REG_MULTI_SZ || RegType == REG_EXPAND_SZ); - - if (bIsStringProperty) - RequiredSizeA = RequiredSizeW / sizeof(WCHAR); - else - RequiredSizeA = RequiredSizeW; - if (RequiredSizeA <= PropertyBufferSize) { if (bIsStringProperty && PropertyBufferSize > 0) @@ -2206,10 +2213,6 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyA( } HeapFree(GetProcessHeap(), 0, PropertyBufferW); - if (PropertyRegDataType) - *PropertyRegDataType = RegType; - if (RequiredSize) - *RequiredSize = RequiredSizeA; return bResult; } @@ -2877,13 +2880,13 @@ BOOL WINAPI SetupDiCallClassInstaller( LPWSTR lpGuidString; if (UuidToStringW((UUID*)&DeviceInfoData->ClassGuid, &lpGuidString) == RPC_S_OK) { - rc = RegQueryValueExW(hKey, L"Installer32", NULL, &dwRegType, NULL, &dwLength); + rc = RegQueryValueExW(hKey, lpGuidString, NULL, &dwRegType, NULL, &dwLength); if (rc == ERROR_SUCCESS && dwRegType == REG_SZ) { LPWSTR KeyBuffer = HeapAlloc(GetProcessHeap(), 0, dwLength); if (KeyBuffer != NULL) { - rc = RegQueryValueExW(hKey, L"Installer32", NULL, NULL, (LPBYTE)KeyBuffer, &dwLength); + rc = RegQueryValueExW(hKey, lpGuidString, NULL, NULL, (LPBYTE)KeyBuffer, &dwLength); if (rc == ERROR_SUCCESS) { LPCWSTR ptr;