mirror of
https://github.com/VSCodium/policy-watcher.git
synced 2025-12-11 19:44:28 -06:00
Support reading longer registry value by dynamically allocating buffer size (#42)
This commit is contained in:
parent
5ec382d087
commit
9b1e64530a
@ -74,18 +74,32 @@ private:
|
|||||||
if (ERROR_SUCCESS != RegOpenKeyEx(root, registryKey.c_str(), 0, KEY_READ, &hKey))
|
if (ERROR_SUCCESS != RegOpenKeyEx(root, registryKey.c_str(), 0, KEY_READ, &hKey))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
BYTE buffer[1024];
|
DWORD bufferSize = 0;
|
||||||
DWORD bufferSize = sizeof(buffer);
|
|
||||||
DWORD type;
|
DWORD type;
|
||||||
|
|
||||||
auto readResult = RegQueryValueEx(hKey, name.c_str(), 0, &type, buffer, &bufferSize);
|
// First query to get required buffer size
|
||||||
|
auto result = RegQueryValueEx(hKey, name.c_str(), 0, &type, nullptr, &bufferSize);
|
||||||
|
|
||||||
|
if (ERROR_SUCCESS != result && ERROR_MORE_DATA != result)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::find(supportedTypes.begin(), supportedTypes.end(), type) == supportedTypes.end())
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<BYTE> buffer(bufferSize);
|
||||||
|
result = RegQueryValueEx(hKey, name.c_str(), 0, &type, buffer.data(), &bufferSize);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (ERROR_SUCCESS != readResult ||
|
if (ERROR_SUCCESS != result)
|
||||||
std::find(supportedTypes.begin(), supportedTypes.end(), type) == supportedTypes.end())
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
return std::optional<T>{parseRegistryValue(buffer, bufferSize, type)};
|
return std::optional<T>{parseRegistryValue(buffer.data(), bufferSize, type)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user