Valhalla Legends Forums Archive | C/C++ Programming | Why doesn't this work

AuthorMessageTime
UserLoser
[code]
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++;
}
}
[/code]

Outputs "Calling...test" twice.  Should be test and test2.  ugh makes no sense
MAX_KEY_LENGTH = 255
September 29, 2006, 3:22 AM
Kp
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.
September 29, 2006, 3:25 AM
UserLoser
Ugh, not setting size was the issue.  Been working on this project too long today.. Thanks
September 29, 2006, 3:30 AM

Search