Hi,
Attached, a better test. The conclusion:
- Values are enumerated in the order they were created, even if a value's been deleted in the meantime. - Key are enumerated alphabetically, irrespective of the order in which they were created.
-- Jon Bright Lead Programmer, Silicon Circus Ltd. http://www.siliconcircus.com
//--------------------------------------------------------------------------- #include <windows.h> #include <stdio.h> #pragma hdrstop //---------------------------------------------------------------------------
int fail(char *stage) { printf("FAILED: %s\n",stage); return -1; }
#pragma argsused int main(int argc, char* argv[]) { HKEY software, wine, valorder, keyorder, k; char name[2]; DWORD i,nsize,type,ri,risize,disp; FILETIME ft;
if (RegCreateKeyEx(HKEY_CURRENT_USER,"Software",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&software,&disp)!=ERROR_SUCCESS) return fail("Create-Software"); if (RegCreateKeyEx(software,"Wine",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&wine,&disp)!=ERROR_SUCCESS) return fail("Create-Wine"); if (RegCreateKeyEx(wine,"TestValOrder",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&valorder,&disp)!=ERROR_SUCCESS) return fail("Create-TestValOrder");
name[1]='\0'; for (i=26; i; i--) { name[0]='A'+i-1; if (RegSetValueEx(valorder,name,0,REG_DWORD,(BYTE*)&i,sizeof(i))!=ERROR_SUCCESS) return fail("SetValueEx"); } for (i=0; i<26; i++) { nsize = 2; risize = sizeof(ri); if (RegEnumValue(valorder,i,name,&nsize,NULL,&type,(BYTE*)&ri,&risize)!=ERROR_SUCCESS) return fail("EnumValue"); printf("%2d. %s = %d\n",i,name,ri); if (ri!=26-i) return fail("Comparison"); }
if (RegDeleteValue(valorder,"C")) return fail("DeleteValue"); i = 1000; if (RegSetValueEx(valorder,"1",0,REG_DWORD,(BYTE*)&i,sizeof(i))!=ERROR_SUCCESS) return fail("SetValueEx"); for (i=0; i<26; i++) { nsize = 2; risize = sizeof(ri); if (RegEnumValue(valorder,i,name,&nsize,NULL,&type,(BYTE*)&ri,&risize)!=ERROR_SUCCESS) return fail("EnumValue"); printf("%2d. %s = %d\n",i,name,ri); if ((i<23 && ri!=26-i) || ((i==23 || i==24) && ri!=25-i) || (i==25 && ri!=1000)) return fail("Comparison"); }
if (RegCloseKey(valorder)!=ERROR_SUCCESS) return fail("CloseKey");
if (RegDeleteKey(wine,"TestValOrder")!=ERROR_SUCCESS) return fail("DeleteKey-Val");
if (RegCreateKeyEx(wine,"TestKeyOrder",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&keyorder,&disp)!=ERROR_SUCCESS) return fail("Create-TestKeyOrder"); name[1]='\0'; for (i=26; i; i--) { name[0]='A'+i-1; if (RegCreateKeyEx(keyorder,name,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&k,&disp)!=ERROR_SUCCESS) return fail("Create-KeyLoop"); if (RegCloseKey(k)!=ERROR_SUCCESS) return fail("Close-KeyLoop"); } for (i=0; i<26; i++) { nsize = 2; if (RegEnumKeyEx(keyorder,i,name,&nsize,NULL,NULL,NULL,&ft)!=ERROR_SUCCESS) return fail("EnumKey"); printf("%2d. %s\n",i,name); if (name[0]!=(char)('A'+i)) return fail("Comparison"); } for (i=0; i<26; i++) { name[0]='A'+i; if (RegDeleteKey(keyorder,name)!=ERROR_SUCCESS) return fail("Delete-KeyLoop"); }
if (RegCloseKey(keyorder)!=ERROR_SUCCESS) return fail("Close-KeyOrder");
if (RegDeleteKey(wine,"TestKeyOrder")!=ERROR_SUCCESS) return fail("DeleteKey-Key");
return 0; } //---------------------------------------------------------------------------