Reads the content of a string registry value and returns it in a std::wstring so that it's easier to manage. Will take care of reallocating buffers as needed. @param p_Key Key containing the value to read. @param p_pValueName Name of value. @param p_rValue Upon exit, will contain the value. @return Error code, or ERROR_SUCCESS if all goes well.
| 411 | // @return Error code, or ERROR_SUCCESS if all goes well. |
| 412 | // |
| 413 | long PluginUtils::ReadRegistryStringValue(const RegKey& p_Key, |
| 414 | const wchar_t* const p_pValueName, |
| 415 | std::wstring& p_rValue) |
| 416 | { |
| 417 | // Clear the content to assume value doesn't exist. |
| 418 | p_rValue.clear(); |
| 419 | |
| 420 | // Loop until we are able to read the value. |
| 421 | long lRes = ERROR_MORE_DATA; |
| 422 | ULONG curSize = 0; |
| 423 | while (lRes == ERROR_MORE_DATA) { |
| 424 | curSize += REG_BUFFER_CHUNK_SIZE; |
| 425 | std::vector<wchar_t> vBuffer(curSize, L'\0'); |
| 426 | DWORD valueType = REG_SZ; |
| 427 | DWORD curSizeInBytes = curSize * sizeof(wchar_t); |
| 428 | lRes = p_Key.QueryValue(p_pValueName, &valueType, vBuffer.data(), &curSizeInBytes); |
| 429 | if (lRes == ERROR_SUCCESS) { |
| 430 | // Make sure it is a string. |
| 431 | if (valueType == REG_SZ && (curSizeInBytes % sizeof(wchar_t)) == 0) { |
| 432 | // Success, copy resulting string. |
| 433 | p_rValue.assign(vBuffer.data()); |
| 434 | } else { |
| 435 | lRes = ERROR_INVALID_DATATYPE; |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | return lRes; |
| 441 | } |
| 442 | |
| 443 | // |
| 444 | // Given a multi-line string read from a REG_MULTI_SZ registry value, |
nothing calls this directly
no test coverage detected