#include <windows.h>
#include <iostream>
using namespace std;
int main() {
HKEY RegKey;
char achKey[80];
long r = RegOpenKeyEx(HKEY_CURRENT_USER,"SOFTWARE",0,KEY_ALL_ACCESS,&RegKey);
if (r==ERROR_SUCCESS) {
int err = 0;
int i = 0;
int counter = 0;
DWORD maxPath = MAX_PATH;
while (err==ERROR_SUCCESS || err == ERROR_MORE_DATA) {
err = RegEnumKeyEx(RegKey, i, achKey, &maxPath, NULL, NULL, NULL, NULL);
i++;
if (err != ERROR_NO_MORE_ITEMS) {
cout << achKey << endl;
counter++;
}
}
}else {
RegCloseKey(RegKey);
}
}
I have tripled-checked the code and cant figure out why it is only showing the first few characters of the full string. Any help is appreciated.
- BlueDev
[edited by - BlueDev on August 17, 2003 12:58:23 AM]
Enumerating Registry
Hi,
I'm having a slight problem with the RegEnumEx function and actually displaying the Folder names.
You should find that the first one is OK - unless it is in fact 4 characters long. You are not resetting the lpcName parameter (maxPath in your case).
This is an in/out variable. You pass in the maximum length the string can be, and the system returns to you the actual length of the string. So you just need to reset maxPath each time around the loop before you call RegEnumKeyEx again.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
[edited by - JY on August 18, 2003 3:47:47 AM]
This is an in/out variable. You pass in the maximum length the string can be, and the system returns to you the actual length of the string. So you just need to reset maxPath each time around the loop before you call RegEnumKeyEx again.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
[edited by - JY on August 18, 2003 3:47:47 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement