Sign in to follow this  

C++ RegGetValue - The sensless 234 error, when reading SZ after DWORD

This topic is 2832 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

This is a part of my code:
WCHAR szMultiSampleType[30];
if(RegGetValue(hKey, NULL, L"AntiAliasingON", RRF_RT_DWORD, NULL, (PVOID)&dwMultiSampleType, &dwDataSize) == ERROR_SUCCESS){
	if(dwMultiSampleType){	
		if((RegGetValue(hKey, NULL, L"D3DMULTISAMPLE_TYPE", RRF_RT_REG_SZ, NULL, (PVOID)szMultiSampleType, &dwDataSize))==ERROR_SUCCESS){
			if(!wcscmp(szMultiSampleType, L"D3DMULTISAMPLE_NONE")) dwMultiSampleType = 0;
			else if(!wcscmp(szMultiSampleType, L"D3DMULTISAMPLE_NONMASKABLE")) dwMultiSampleType = 1;
			else swscanf(szMultiSampleType, L"D3DMULTISAMPLE_%d_SAMPLES", &dwMultiSampleType);
			RegGetValue(hKey, NULL, L"MultiSampleQuality", RRF_RT_DWORD, NULL, (PVOID)&dwMultiSampleQuality, &dwDataSize);
		}
	}
}
When it tries to read the SZ, it returns 234 (more data availible). I dont understand this - the returned size is 56, so the buffer (szMultiSampleType) should handle it. I have also tried to increase its size, but with the same result. The strangest thing: When I move the getting of the SZ before DWORDs, it is OK, but I need to read some DWORDs before that. Any idea? THX

Share this post


Link to post
Share on other sites
I have figured it out. The last parameter (pcbData) is not just output parameter, its in/out and it has to be set to the size of the buffer in bytes.

So, because I have not initialized the dwDataSize, I was just (un)lucky - there was a big number and after reading DWORD it was set to 4, which was not enough for the SZ string. When SZ is read first, it sets dwDataSize to 54, which is enough for the DWORD.

Also, I have read, that RegGetValue is supported since Windows XP x64, so I have converted to RegQueryValueEx - but it requires the same last parameter - now solved :-)

Share this post


Link to post
Share on other sites

This topic is 2832 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this