views:

30

answers:

1

In MSDN it says that RegEnumValue should not be used when calling function that change the registry keys being enumerated.

So does this also apply to deleting registry key values?

Like this code does:

if (RegOpenKeyEx(m_hkey,m_path.c_str(),0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS)
 {
  bool error=false;
  idx=0;
  while (RegEnumValue(key,idx,name,&namesize,NULL,NULL,NULL,NULL) == ERROR_SUCCESS && !error)
  {
   error=(RegDeleteValue(key,name)!=ERROR_SUCCESS);
   idx++;
  }
  RegCloseKey(key);
 }
+2  A: 

Your code does not work. When you delete index 0, the next item becomes index 0, and you do not delete that.

So yes, it applies to deleting key values.

Christopher