This class is not thread safe. Wait for Revision 6.
Posted by mmoore
on 04/29/2009 02:15pm
In http://msdn.microsoft.com/en-us/library/ms724836(VS.85).aspx we find this:
"The predefined handles are not thread safe. Closing a predefined handle in one thread affects any other threads that are using the handle."
This means that it is not legitimate to call RegCloseKey on a predefined handle such as HKEY_LOCAL_MACHINE, but this class will do that if you create a class object with a predefined key. This causes intermittent failures of registry access in other threads of the same application.
We are trying to notify the author of this problem and we are confident he will shortly provide revised code.
Work-around until Revision 6.
Posted by KevinSorensen
on 04/29/2009 02:26pm
In the meantime we do the following before every RegCloseKey( hKey_p ) call:
if (!IsPredefined( hKey_p ))
RegCloseKey( hKey_p );
Where IsPredefined is the following:
BOOL CRegistry::IsPredefined( HKEY hKey )
return ((hKey == HKEY_CLASSES_ROOT) ||
(hKey == HKEY_CURRENT_CONFIG) ||
(hKey == HKEY_CURRENT_USER) ||
(hKey == HKEY_LOCAL_MACHINE) ||
(hKey == HKEY_PERFORMANCE_DATA) ||
(hKey == HKEY_PERFORMANCE_NLSTEXT) ||
(hKey == HKEY_PERFORMANCE_TEXT) ||
(hKey == HKEY_USERS));
I am getting question marks at the end of retrieved strings. I believe it is only occurring when the build is unicode.
// value is set
sValue = m_sPrevFontName; // value is "Arial"
User.SaveKey(sKey, TEXT("PrevFontName"), sValue);
// value is retrieved
if (User.LoadKey(sKey, TEXT("PrevFontName"), sValue))
m_sPrevFontName = sValue;
now sValue is "Arial???????"
I can't get the way for connecting a remote registry, nor using the RegConnectRegistry() API function, neither using a wrapper class that i'm trying to implement. What is wrong in a call to the API functions that looks