thpatch / thcrap

Touhou Community Reliant Automatic Patcher
https://www.thpatch.net
The Unlicense
551 stars 41 forks source link

RegGetValueW missing on XP 32-bits #193

Closed brliron closed 1 year ago

brliron commented 2 years ago

The RegGetValueW function doesn't exist on Windows XP 32-bits (https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluew). We only use it in one place, which is games auto-detection from installed programs in the configure tool.

We could either load it with GetProcAddress, and break the feature on XP (not that much of a problem, the manual search still works), or use a different function that exists on XP.

DankRank commented 2 years ago
static std::wstring GetValueFromKey(HKEY key, LPCWSTR subkey, LPCWSTR valueName)
{
    LSTATUS ret;
    std::vector<WCHAR> value;
    DWORD valueSize = 64;
    HKEY hSub;
    DWORD type = 0;

    if (RegOpenKeyExA(key, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hSub)) {
        return false;
    }

    do {
        value.resize(valueSize);
        ret = RegQueryValueExW(hSub, valueName, 0, &type, value.data(), &valueSize);
    } while (ret == ERROR_MORE_DATA);
    RegCloseKey(hSub);
    if (ret != ERROR_SUCCESS || type != REG_SZ) {
        return false;
    }

    return std::wstring(value.data(), valueSize);
}