Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: UserLoser on September 28, 2006, 10:22 PM

Title: Why doesn't this work
Post by: UserLoser on September 28, 2006, 10:22 PM

void Registry::EnumKeys(EnumKeyCallback Callback)
{
char KeyName[MAX_KEY_LENGTH];
DWORD Size;
int Index = 0;
while(RegEnumKeyEx(hKey, Index, KeyName, &Size, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS) {
OutputDebugString("Calling...");
OutputDebugString(KeyName);
OutputDebugString("\n");
//Callback(KeyName);
Index++;
}
}


Outputs "Calling...test" twice.  Should be test and test2.  ugh makes no sense
MAX_KEY_LENGTH = 255
Title: Re: Why doesn't this work
Post by: Kp on September 28, 2006, 10:25 PM
Perhaps the second pass returns a failure code (other than ERROR_NO_MORE_ITEMS), leading you to run the loop with stale data?

Also, you should initialize Size on each iteration.  RegEnumKeyEx reads it on startup and modifies it before returning.
Title: Re: Why doesn't this work
Post by: UserLoser on September 28, 2006, 10:30 PM
Ugh, not setting size was the issue.  Been working on this project too long today.. Thanks