Silly Question On Setting Registry
I found a strange problem with setting and reading a string value inside the registry. I need to read the value twice to get the string value out.
error = RegQueryValueEx(hk, "MySubKey", NULL, &dwType, NULL, &dwLength);
if(error == ERROR_SUCCESS)
{
RegQueryValueEx(hk, "MySubKey", NULL, &dwType,
(LPBYTE)Buffer, &dwLength);
}
Otherwise I get an error code 234 (ERROR_MORE_DATA). Is this normal? I call
RegSetValueEx(hk, "MySubKey",0, REG_SZ,(LPBYTE)Buffer,(strlen(Buffer) + 1));
and check the registry. It looks fine. Thanks for any help. Sorry for the weird code spacing.
You need to set dwLength to be the size of your buffer before you make the first call. The second one should become unnecessary.
If you check the docs for RegQueryValueEx, you'll see lpcbData is marked with [in, out] - this means that the values it contains both before and after the function are meaningful.
If you check the docs for RegQueryValueEx, you'll see lpcbData is marked with [in, out] - this means that the values it contains both before and after the function are meaningful.
The dwLength parameter is used on input to tell RegQueryValueEx how big your output buffer is. If dwLength is too small to contain the value, RegQueryValueEx returns ERROR_MORE_DATA and sets dwLength to the size needed to hold the value. This allows you to resize your buffer, if needed, to retrieve the value.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement