Hi. I'm trying to read some ODBC details from a registry and for that I use RegQueryValueEx. The problem is when I compile the release version it simply cannot read any registry values.
The code is:
CString odbcFuns::getOpenedKeyRegValue(HKEY hKey, CString valName)
{
CString retStr;
char *strTmp = (char*)malloc(MAX_DSN_STR_LENGTH * sizeof(char));
memset(strTmp, 0, MAX_DSN_STR_LENGTH);
DWORD cbData;
long rret = RegQueryValueEx(hKey, valName, NULL, NULL, (LPBYTE)strTmp, &cbData);
if (rret != ERROR_SUCCESS)
{
free(strTmp);
return CString("?");
}
strTmp[cbData] = '\0';
retStr.Format(_T("%s"), strTmp);
free(strTmp);
return retStr;
}
I've found a workaround for this - I disabled Optimization (/Od), but it seems strange that I needed to do that. Is there some other way? I use Visual Studio 2005. Maybe it's a bug in VS?
Almost forgot - the error code is 2 (as the key wouldn't be found).