<p>Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I:</p>

<ol>
<li>Safely determine that such a key exists.</li>
<li>Programmatically (i.e. with code) get its value.</li>
</ol>

<p>I have absolutely no intention of writing anything back to the registry (for the duration of my career if I can help it). So we can skip the lecture about every molecule in my body exploding at the speed of light if I write to the registry incorrectly. </p>

<p>Prefer answers in C++, but mostly just need to know what the special Windows API incantation to get at the value is.</p>

[{'answer_id': 34067, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms724911%28VS.85%29.aspx" rel="nofollow noreferrer">RegQueryValueEx</a></p>\n\n<p>This gives the value if it exists, and returns an error code ERROR_FILE_NOT_FOUND if the key doesn\'t exist.</p>\n\n<p>(I can\'t tell if my link is working or not, but if you just google for "RegQueryValueEx" the first hit is the msdn documentation.)</p>\n'}, {'answer_id': 34071, 'author': 'Serge', 'author_id': 1007, 'author_profile': 'https://Stackoverflow.com/users/1007', 'pm_score': 3, 'selected': False, 'text': '<p>The pair <a href="http://msdn.microsoft.com/en-us/library/ms724895%28VS.85%29.aspx" rel="noreferrer">RegOpenKey</a> and <a href="http://msdn.microsoft.com/en-us/library/ms724911%28VS.85%29.aspx" rel="noreferrer">RegQueryKeyEx</a> will do the trick.</p>\n\n<p>If you use MFC <a href="http://msdn.microsoft.com/en-us/library/xka57xy4%28VS.80%29.aspx" rel="noreferrer">CRegKey</a> class is even more easier solution.</p>\n'}, {'answer_id': 34082, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 3, 'selected': False, 'text': '<pre><code>const CString REG_SW_GROUP_I_WANT = _T("SOFTWARE\\\\My Corporation\\\\My Package\\\\Group I want");\nconst CString REG_KEY_I_WANT= _T("Key Name");\n\nCRegKey regKey;\nDWORD   dwValue = 0;\n\nif(ERROR_SUCCESS != regKey.Open(HKEY_LOCAL_MACHINE, REG_SW_GROUP_I_WANT))\n{\n  m_pobLogger-&gt;LogError(_T("CRegKey::Open failed in Method"));\n  regKey.Close();\n  goto Function_Exit;\n}\nif( ERROR_SUCCESS != regKey.QueryValue( dwValue, REG_KEY_I_WANT))\n{\n  m_pobLogger-&gt;LogError(_T("CRegKey::QueryValue Failed in Method"));\n  regKey.Close();\n  goto Function_Exit;\n}\n\n// dwValue has the stuff now - use for further processing\n</code></pre>\n'}, {'answer_id': 35717, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 7, 'selected': True, 'text': '<p><strong>Here is some pseudo-code to retrieve the following:</strong></p>\n\n<ol>\n<li>If a registry key exists</li>\n<li>What the default value is for that registry key</li>\n<li>What a string value is</li>\n<li>What a DWORD value is</li>\n</ol>\n\n<p><strong>Example code:</strong></p>\n\n<p>Include the library dependency: Advapi32.lib</p>\n\n<pre><code>HKEY hKey;\nLONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\\\Perl", 0, KEY_READ, &amp;hKey);\nbool bExistsAndSuccess (lRes == ERROR_SUCCESS);\nbool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);\nstd::wstring strValueOfBinDir;\nstd::wstring strKeyDefaultValue;\nGetStringRegKey(hKey, L"BinDir", strValueOfBinDir, L"bad");\nGetStringRegKey(hKey, L"", strKeyDefaultValue, L"bad");\n\nLONG GetDWORDRegKey(HKEY hKey, const std::wstring &amp;strValueName, DWORD &amp;nValue, DWORD nDefaultValue)\n{\n    nValue = nDefaultValue;\n    DWORD dwBufferSize(sizeof(DWORD));\n    DWORD nResult(0);\n    LONG nError = ::RegQueryValueExW(hKey,\n        strValueName.c_str(),\n        0,\n        NULL,\n        reinterpret_cast&lt;LPBYTE&gt;(&amp;nResult),\n        &amp;dwBufferSize);\n    if (ERROR_SUCCESS == nError)\n    {\n        nValue = nResult;\n    }\n    return nError;\n}\n\n\nLONG GetBoolRegKey(HKEY hKey, const std::wstring &amp;strValueName, bool &amp;bValue, bool bDefaultValue)\n{\n    DWORD nDefValue((bDefaultValue) ? 1 : 0);\n    DWORD nResult(nDefValue);\n    LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue);\n    if (ERROR_SUCCESS == nError)\n    {\n        bValue = (nResult != 0) ? true : false;\n    }\n    return nError;\n}\n\n\nLONG GetStringRegKey(HKEY hKey, const std::wstring &amp;strValueName, std::wstring &amp;strValue, const std::wstring &amp;strDefaultValue)\n{\n    strValue = strDefaultValue;\n    WCHAR szBuffer[512];\n    DWORD dwBufferSize = sizeof(szBuffer);\n    ULONG nError;\n    nError = RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, (LPBYTE)szBuffer, &amp;dwBufferSize);\n    if (ERROR_SUCCESS == nError)\n    {\n        strValue = szBuffer;\n    }\n    return nError;\n}\n</code></pre>\n'}, {'answer_id': 7199329, 'author': 'Jim Michaels', 'author_id': 591668, 'author_profile': 'https://Stackoverflow.com/users/591668', 'pm_score': 0, 'selected': False, 'text': '<pre><code>#include &lt;windows.h&gt;\n#include &lt;map&gt;\n#include &lt;string&gt;\n#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n#include &lt;tr1/stdint.h&gt;\n\nusing namespace std;\n\nvoid printerr(DWORD dwerror) {\n    LPVOID lpMsgBuf;\n    FormatMessage(\n        FORMAT_MESSAGE_ALLOCATE_BUFFER |\n        FORMAT_MESSAGE_FROM_SYSTEM |\n        FORMAT_MESSAGE_IGNORE_INSERTS,\n        NULL,\n        dwerror,\n        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\n        (LPTSTR) &amp;lpMsgBuf,\n        0,\n        NULL\n    );\n    // Process any inserts in lpMsgBuf.\n    // ...\n    // Display the string.\n    if (isOut) {\n        fprintf(fout, "%s\\n", lpMsgBuf);\n    } else {\n        printf("%s\\n", lpMsgBuf);\n    }\n    // Free the buffer.\n    LocalFree(lpMsgBuf);\n}\n\n\n\nbool regreadSZ(string&amp; hkey, string&amp; subkey, string&amp; value, string&amp; returnvalue, string&amp; regValueType) {\n    char s[128000];\n    map&lt;string,HKEY&gt; keys;\n    keys["HKEY_CLASSES_ROOT"]=HKEY_CLASSES_ROOT;\n    keys["HKEY_CURRENT_CONFIG"]=HKEY_CURRENT_CONFIG; //DID NOT SURVIVE?\n    keys["HKEY_CURRENT_USER"]=HKEY_CURRENT_USER;\n    keys["HKEY_LOCAL_MACHINE"]=HKEY_LOCAL_MACHINE;\n    keys["HKEY_USERS"]=HKEY_USERS;\n    HKEY mykey;\n\n    map&lt;string,DWORD&gt; valuetypes;\n    valuetypes["REG_SZ"]=REG_SZ;\n    valuetypes["REG_EXPAND_SZ"]=REG_EXPAND_SZ;\n    valuetypes["REG_MULTI_SZ"]=REG_MULTI_SZ; //probably can\'t use this.\n\n    LONG retval=RegOpenKeyEx(\n        keys[hkey],         // handle to open key\n        subkey.c_str(),  // subkey name\n        0,   // reserved\n        KEY_READ, // security access mask\n        &amp;mykey    // handle to open key\n    );\n    if (ERROR_SUCCESS != retval) {printerr(retval); return false;}\n    DWORD slen=128000;\n    DWORD valuetype = valuetypes[regValueType];\n    retval=RegQueryValueEx(\n      mykey,            // handle to key\n      value.c_str(),  // value name\n      NULL,   // reserved\n      (LPDWORD) &amp;valuetype,       // type buffer\n      (LPBYTE)s,        // data buffer\n      (LPDWORD) &amp;slen      // size of data buffer\n    );\n    switch(retval) {\n        case ERROR_SUCCESS:\n            //if (isOut) {\n            //    fprintf(fout,"RegQueryValueEx():ERROR_SUCCESS:succeeded.\\n");\n            //} else {\n            //    printf("RegQueryValueEx():ERROR_SUCCESS:succeeded.\\n");\n            //}\n            break;\n        case ERROR_MORE_DATA:\n            //what do I do now?  data buffer is too small.\n            if (isOut) {\n                fprintf(fout,"RegQueryValueEx():ERROR_MORE_DATA: need bigger buffer.\\n");\n            } else {\n                printf("RegQueryValueEx():ERROR_MORE_DATA: need bigger buffer.\\n");\n            }\n            return false;\n        case ERROR_FILE_NOT_FOUND:\n            if (isOut) {\n                fprintf(fout,"RegQueryValueEx():ERROR_FILE_NOT_FOUND: registry value does not exist.\\n");\n            } else {\n                printf("RegQueryValueEx():ERROR_FILE_NOT_FOUND: registry value does not exist.\\n");\n            }\n            return false;\n        default:\n            if (isOut) {\n                fprintf(fout,"RegQueryValueEx():unknown error type 0x%lx.\\n", retval);\n            } else {\n                printf("RegQueryValueEx():unknown error type 0x%lx.\\n", retval);\n            }\n            return false;\n\n    }\n    retval=RegCloseKey(mykey);\n    if (ERROR_SUCCESS != retval) {printerr(retval); return false;}\n\n    returnvalue = s;\n    return true;\n}\n</code></pre>\n'}, {'answer_id': 50821858, 'author': 'Roi Danton', 'author_id': 4566599, 'author_profile': 'https://Stackoverflow.com/users/4566599', 'pm_score': 3, 'selected': False, 'text': '<p>Since Windows >=Vista/Server 2008, <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724868(v=vs.85).aspx" rel="noreferrer">RegGetValue</a> is available, which <a href="https://msdn.microsoft.com/en-us/magazine/mt808504.aspx" rel="noreferrer">is a safer function</a> than <a href="https://msdn.microsoft.com/en-us/library/ms724911%28VS.85%29.aspx" rel="noreferrer">RegQueryValueEx</a>. No need for <code>RegOpenKeyEx</code>, <code>RegCloseKey</code> or <code>NUL</code> termination checks of string values (<a href="https://msdn.microsoft.com/en-us/library/ms724884(v=vs.85).aspx" rel="noreferrer"><code>REG_SZ</code>, <code>REG_MULTI_SZ</code>, <code>REG_EXPAND_SZ</code></a>).</p>\n\n<pre><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;exception&gt;\n#include &lt;windows.h&gt;\n\n/*! \\brief                          Returns a value from HKLM as string.\n    \\exception  std::runtime_error  Replace with your error handling.\n*/\nstd::wstring GetStringValueFromHKLM(const std::wstring&amp; regSubKey, const std::wstring&amp; regValue)\n{\n    size_t bufferSize = 0xFFF; // If too small, will be resized down below.\n    std::wstring valueBuf; // Contiguous buffer since C++11.\n    valueBuf.resize(bufferSize);\n    auto cbData = static_cast&lt;DWORD&gt;(bufferSize * sizeof(wchar_t));\n    auto rc = RegGetValueW(\n        HKEY_LOCAL_MACHINE,\n        regSubKey.c_str(),\n        regValue.c_str(),\n        RRF_RT_REG_SZ,\n        nullptr,\n        static_cast&lt;void*&gt;(valueBuf.data()),\n        &amp;cbData\n    );\n    while (rc == ERROR_MORE_DATA)\n    {\n        // Get a buffer that is big enough.\n        cbData /= sizeof(wchar_t);\n        if (cbData &gt; static_cast&lt;DWORD&gt;(bufferSize))\n        {\n            bufferSize = static_cast&lt;size_t&gt;(cbData);\n        }\n        else\n        {\n            bufferSize *= 2;\n            cbData = static_cast&lt;DWORD&gt;(bufferSize * sizeof(wchar_t));\n        }\n        valueBuf.resize(bufferSize);\n        rc = RegGetValueW(\n            HKEY_LOCAL_MACHINE,\n            regSubKey.c_str(),\n            regValue.c_str(),\n            RRF_RT_REG_SZ,\n            nullptr,\n            static_cast&lt;void*&gt;(valueBuf.data()),\n            &amp;cbData\n        );\n    }\n    if (rc == ERROR_SUCCESS)\n    {\n        cbData /= sizeof(wchar_t);\n        valueBuf.resize(static_cast&lt;size_t&gt;(cbData - 1)); // remove end null character\n        return valueBuf;\n    }\n    else\n    {\n        throw std::runtime_error("Windows system error code: " + std::to_string(rc));\n    }\n}\n\nint main()\n{\n    std::wstring regSubKey;\n#ifdef _WIN64 // Manually switching between 32bit/64bit for the example. Use dwFlags instead.\n    regSubKey = L"SOFTWARE\\\\WOW6432Node\\\\Company Name\\\\Application Name\\\\";\n#else\n    regSubKey = L"SOFTWARE\\\\Company Name\\\\Application Name\\\\";\n#endif\n    std::wstring regValue(L"MyValue");\n    std::wstring valueFromRegistry;\n    try\n    {\n        valueFromRegistry = GetStringValueFromHKLM(regSubKey, regValue);\n    }\n    catch (std::exception&amp; e)\n    {\n        std::cerr &lt;&lt; e.what();\n    }\n    std::wcout &lt;&lt; valueFromRegistry;\n}\n</code></pre>\n\n<p>Its parameter <code>dwFlags</code> supports flags for type restriction, filling the value buffer with zeros on failure (<code>RRF_ZEROONFAILURE</code>) and 32/64bit registry access (<code>RRF_SUBKEY_WOW6464KEY</code>, <code>RRF_SUBKEY_WOW6432KEY</code>) for 64bit programs.</p>\n'}, {'answer_id': 53074007, 'author': 'kayleeFrye_onDeck', 'author_id': 3543437, 'author_profile': 'https://Stackoverflow.com/users/3543437', 'pm_score': 1, 'selected': False, 'text': '<p>This console app will list all the values and their data from a registry key for most of the potential registry values. There\'s some weird ones not often used. If you need to support all of them, expand from this example while referencing this <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb773476(v=vs.85).aspx" rel="nofollow noreferrer">Registry Value Type</a> documentation.</p>\n\n<p>Let this be the registry key content you can import from a <code>.reg</code> file format:</p>\n\n<pre><code>Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\added\\subkey]\n"String_Value"="hello, world!"\n"Binary_Value"=hex:01,01,01,01\n"Dword value"=dword:00001224\n"QWord val"=hex(b):24,22,12,00,00,00,00,00\n"multi-line val"=hex(7):4c,00,69,00,6e,00,65,00,20,00,30,00,00,00,4c,00,69,00,\\\n  6e,00,65,00,20,00,31,00,00,00,4c,00,69,00,6e,00,65,00,20,00,32,00,00,00,00,\\\n  00\n"expanded_val"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,\\\n  00,4c,00,45,00,25,00,5c,00,6e,00,65,00,77,00,5f,00,73,00,74,00,75,00,66,00,\\\n  66,00,00,00\n</code></pre>\n\n<p>The console app itself:</p>\n\n<pre><code>#include &lt;Windows.h&gt;\n#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;locale&gt;\n#include &lt;vector&gt;\n#include &lt;iomanip&gt;\n\nint wmain()\n{\n    const auto hKey = HKEY_CURRENT_USER;\n    constexpr auto lpSubKey = TEXT("added\\\\subkey");\n    auto openedKey = HKEY();\n    auto status = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &amp;openedKey);\n\n    if (status == ERROR_SUCCESS) {\n        auto valueCount = static_cast&lt;DWORD&gt;(0);\n        auto maxNameLength = static_cast&lt;DWORD&gt;(0);\n        auto maxValueLength = static_cast&lt;DWORD&gt;(0);\n        status = RegQueryInfoKey(openedKey, NULL, NULL, NULL, NULL, NULL, NULL,\n            &amp;valueCount, &amp;maxNameLength, &amp;maxValueLength, NULL, NULL);\n\n        if (status == ERROR_SUCCESS) {\n            DWORD type = 0;\n            DWORD index = 0;\n            std::vector&lt;wchar_t&gt; valueName = std::vector&lt;wchar_t&gt;(maxNameLength + 1);\n            std::vector&lt;BYTE&gt; dataBuffer = std::vector&lt;BYTE&gt;(maxValueLength);\n\n            for (DWORD index = 0; index &lt; valueCount; index++) {\n                DWORD charCountValueName = static_cast&lt;DWORD&gt;(valueName.size());\n                DWORD charBytesData = static_cast&lt;DWORD&gt;(dataBuffer.size());\n                status = RegEnumValue(openedKey, index, valueName.data(), &amp;charCountValueName,\n                    NULL, &amp;type, dataBuffer.data(), &amp;charBytesData);\n\n                if (type == REG_SZ) {\n                    const auto reg_string = reinterpret_cast&lt;wchar_t*&gt;(dataBuffer.data());\n                    std::wcout &lt;&lt; L"Type: REG_SZ" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData : " &lt;&lt; reg_string &lt;&lt; std::endl;\n                }\n                else if (type == REG_EXPAND_SZ) {\n                    const auto casted = reinterpret_cast&lt;wchar_t*&gt;(dataBuffer.data());\n                    TCHAR buffer[32000];\n                    ExpandEnvironmentStrings(casted, buffer, 32000);\n                    std::wcout &lt;&lt; L"Type: REG_EXPAND_SZ" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData: " &lt;&lt; buffer &lt;&lt; std::endl;\n                }\n                else if (type == REG_MULTI_SZ) {\n                    std::vector&lt;std::wstring&gt; lines;\n                    const auto str = reinterpret_cast&lt;wchar_t*&gt;(dataBuffer.data());\n                    auto line = str;\n                    lines.emplace_back(line);\n                    for (auto i = 0; i &lt; charBytesData / sizeof(wchar_t) - 1; i++) {\n                        const auto c = str[i];\n                        if (c == 0) {\n                            line = str + i + 1;\n                            const auto new_line = reinterpret_cast&lt;wchar_t*&gt;(line);\n                            if (wcsnlen_s(new_line, 1024) &gt; 0)\n                                lines.emplace_back(new_line);\n                        }\n                    }\n                    std::wcout &lt;&lt; L"Type: REG_MULTI_SZ" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData: " &lt;&lt; std::endl;\n                    for (size_t i = 0; i &lt; lines.size(); i++) {\n                        std::wcout &lt;&lt; L"\\t\\tLine[" &lt;&lt; i + 1 &lt;&lt; L"]: " &lt;&lt; lines[i] &lt;&lt; std::endl;\n                    }\n                }\n                if (type == REG_DWORD) {\n                    const auto dword_value = reinterpret_cast&lt;unsigned long*&gt;(dataBuffer.data());\n                    std::wcout &lt;&lt; L"Type: REG_DWORD" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData : " &lt;&lt; std::to_wstring(*dword_value) &lt;&lt; std::endl;\n                }\n                else if (type == REG_QWORD) {\n                    const auto qword_value = reinterpret_cast&lt;unsigned long long*&gt;(dataBuffer.data());\n                    std::wcout &lt;&lt; L"Type: REG_DWORD" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData : " &lt;&lt; std::to_wstring(*qword_value) &lt;&lt; std::endl;\n                }\n                else if (type == REG_BINARY) {\n                    std::vector&lt;uint16_t&gt; bins;\n                    for (auto i = 0; i &lt; charBytesData; i++) {\n                        bins.push_back(static_cast&lt;uint16_t&gt;(dataBuffer[i]));\n                    }\n                    std::wcout &lt;&lt; L"Type: REG_BINARY" &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tName: " &lt;&lt; valueName.data() &lt;&lt; std::endl;\n                    std::wcout &lt;&lt; L"\\tData:";\n                    for (size_t i = 0; i &lt; bins.size(); i++) {\n                        std::wcout &lt;&lt; L" " &lt;&lt; std::uppercase &lt;&lt; std::hex &lt;&lt; \\\n                            std::setw(2) &lt;&lt; std::setfill(L\'0\') &lt;&lt; std::to_wstring(bins[i]);\n                    }\n                    std::wcout &lt;&lt; std::endl;\n                }\n            }\n        }\n    }\n\n    RegCloseKey(openedKey);\n    return 0;\n}\n</code></pre>\n\n<p>Expected console output: </p>\n\n<pre><code>Type: REG_SZ\n        Name: String_Value\n        Data : hello, world!\nType: REG_BINARY\n        Name: Binary_Value\n        Data: 01 01 01 01\nType: REG_DWORD\n        Name: Dword value\n        Data : 4644\nType: REG_DWORD\n        Name: QWord val\n        Data : 1188388\nType: REG_MULTI_SZ\n        Name: multi-line val\n        Data:\n                Line[1]: Line 0\n                Line[2]: Line 1\n                Line[3]: Line 2\nType: REG_EXPAND_SZ\n        Name: expanded_val\n        Data: C:\\Users\\user name\\new_stuff\n</code></pre>\n'}, {'answer_id': 57627988, 'author': 'Jarek C', 'author_id': 3736444, 'author_profile': 'https://Stackoverflow.com/users/3736444', 'pm_score': 2, 'selected': False, 'text': '<p>Typically the register key and value are constants in the program. If so, here is an example how to read a DWORD registry value <code>Computer\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\\LongPathsEnabled</code>:</p>\n\n<pre><code>#include &lt;windows.h&gt;\n\nDWORD val;\nDWORD dataSize = sizeof(val);\nif (ERROR_SUCCESS == RegGetValueA(HKEY_LOCAL_MACHINE, "SYSTEM\\\\CurrentControlSet\\\\Control\\\\FileSystem", "LongPathsEnabled", RRF_RT_DWORD, nullptr /*type not required*/, &amp;val, &amp;dataSize)) {\n  printf("Value is %i\\n", val);\n  // no CloseKey needed because it is a predefined registry key\n}\nelse {\n  printf("Error reading.\\n");\n}\n</code></pre>\n\n<p>To adapt for other value types, see <a href="https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluea" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluea</a> for complete spec.</p>\n'}]
['https://Stackoverflow.com/questions/34065', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3551/']