Jump to content
  • Advertisement
Sign in to follow this  
fathom88

Silly Question On Setting Registry

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!