Checho Checho - 6 months ago 35
C Question

Error code 87 with RegEnumValue

I am trying to show a single value's name using RegEnumValue (I can use RegGetValue, but i'm trying to learn how to use the RegEnumValue function), but I'm getting the error code 87, "The parameter is incorrect".

Here's my code:

int wmain()
LPCWSTR subKey = L"WinSide";
DWORD options = 0;
HKEY pkOpenResult;

DWORD index = 0;
WCHAR valueName[16383];
LPWSTR pValueName = valueName;
DWORD size=sizeof(valueName);
DWORD reserved = NULL;
DWORD type;
WCHAR data[255];
LPWSTR pData=data;
DWORD sizeData = sizeof(data);

LONG openKey = RegOpenKeyEx(hKey, subKey, options, samDesired, &pkOpenResult);

if (openKey != ERROR_SUCCESS)
wprintf(L"Error opening the key. Code: %li\n");
wprintf(L"Key opened!\n");

LONG enumValue = RegEnumValue(pkOpenResult, index, pValueName, &size,
&reserved, &type, pData, &sizeData);

if (enumValue != ERROR_SUCCESS)
wprintf(L"Error code: %li\n", enumValue);
wprintf(L"Going to show the value's name here!");


return 0;

What am I doing wrong?

So sorry for any mistake.


lpReserved must be NULL as stated in the documentation. You pass a non-null value. That is the reason for the failure. Remove the reserved variable and simply pass NULL for lpReserved.

The lpcchValueName argument specifies characters rather than bytes. You pass the number of bytes in error. That mistake won't necessarily hurt you now but there is a buffer overrun error in the making there so you do need to fix it.