Error 234, more data is available, with RegQueryInfoKey and RegEnumValue
<p>I am trying to use <code>RegQueryInfoKey</code> to get the longest value and data´s size and then <code>RegEnumValue</code> to show all the values, but I am getting the 234 error value, which means "More data is available" when I run the app. </p>

<p>I am also using <code>malloc</code> to allocate <code>lpValueName</code> and <code>lpData</code> so I can use the sizes that <code>RegQueryInfoKey</code> gave me. </p>

<p>If i set <code>lpcchValueName</code> to 16383, for example, the app works just fine, but it no idea why it doesn't with the <code>lpcMaxSubKeyLen</code> value returned by <code>RegQueryInfoKey</code>.</p>

<p>The registry key has two string values:
<a href="https://i.stack.imgur.com/mXMVt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mXMVt.png" alt="HKCU\WinSide string values"></a></p>

<p>What am I doing wrong? Apologize for all the noob errors you might see. Here is my code: </p>

<pre><code>int wmain()
{
    //RegOpenKeyEx
    HKEY hKey = HKEY_CURRENT_USER;
    LPCWSTR subKey = L"WinSide";
    DWORD options = 0;
    REGSAM samDesired = KEY_QUERY_VALUE;
    HKEY hkOpenResult;

    //Opening the HKEY_CURRENT_USER\WinSide subkey
    LONG openKey = RegOpenKeyEx(hKey, subKey, options,
                            samDesired, &amp;hkOpenResult);

    if (openKey != ERROR_SUCCESS)
        wprintf(L"Error code: %li\n", openKey);
    else
    {
        wprintf(L"Key opened!\n");

        //RegQueryInfoKey
        LPWSTR pClass = NULL;
        LPDWORD pcClass = NULL;
        LPDWORD reserved = NULL;
        DWORD numberOfSubKeys;
        LPDWORD pcMaxSubKeyLen = NULL;
        LPDWORD pcMaxClassLen = NULL;
        DWORD numberOfValues;
        DWORD longestValueName;
        DWORD longestDataComponent;
        LPDWORD securityDescriptor = NULL;
        PFILETIME pLastWriteTime = NULL;

        //Querying info from HKCU\WinSide subkey
        LONG queryInfo = RegQueryInfoKey(hkOpenResult, pClass, pcClass, reserved, &amp;numberOfSubKeys,
                                        pcMaxSubKeyLen, pcMaxClassLen, &amp;numberOfValues,
                                        &amp;longestValueName, &amp;longestDataComponent,
                                        securityDescriptor, pLastWriteTime);

        if (queryInfo != ERROR_SUCCESS)
            wprintf(L"Error code: %li\n", queryInfo);
        else
        {
            wprintf(L"Key queried!\n");
            wprintf(L"Number of values: %u\n", numberOfValues);

            //RegEnumValue
            DWORD index=0;
            DWORD sizedem = sizeof(WCHAR);
            LPWSTR nameOfValue = (LPWSTR)malloc(longestValueName * sizeof(WCHAR));
            DWORD sizeOfBufffer = longestValueName;
            DWORD typeOfDataStored;
            LPBYTE pData = (LPBYTE)malloc(longestDataComponent * sizeof(BYTE));
            DWORD sizeOfData = longestDataComponent;

            if (nameOfValue != NULL &amp;&amp; pData != NULL)
            {
                for (index = 0; index &lt; numberOfValues; index++)
                {
                    sizeOfBufffer = longestValueName;

                    //Enumerating values from HKCU\WinSide subkey
                    LONG enuValue = RegEnumValue(hkOpenResult, index, nameOfValue,
                        &amp;sizeOfBufffer, NULL, &amp;typeOfDataStored,
                        pData, &amp;sizeOfData);

                    if (enuValue != ERROR_SUCCESS)
                        wprintf(L"Error code: %li\n", enuValue);
                    else
                    {
                        wprintf(L"Value: %s\n", (LPWSTR)pData);

                    }

                }

            }
            else
            {
                wprintf(L"Memory could not be allocated.\n");
            }       



            free(nameOfValue);
            free(pData);


        }



        RegCloseKey(hkOpenResult);
    }

    return 0;

}
</code></pre>

<p>This is my result:</p>

<p><a href="https://i.stack.imgur.com/TFYw5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TFYw5.png" alt="Result"></a></p>

<p>Thanks a lot!</p>