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

## Recommended Posts

prophet tx-7    100
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 on other sites
prophet tx-7    100
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 :-)