Enumerating Registry

Started by
2 comments, last by BlueDev 20 years, 8 months ago
Hi, I'm having a slight problem with the RegEnumEx function and actually displaying the Folder names.

#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    BlueDev Net [edited by - BlueDev on August 17, 2003 12:58:23 AM]
[/quote]
Advertisement
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]
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Ok, thanks for the help, and also ill figure out how to reset the maxPath each time around. I once tried ''maxPath = 0'' each time but now all strings come out to be ''!'' but I think I have to do something differently but it''ll show itself, hehe.

- BlueDev
[/quote]
Well, nevermind, I figured it out. Thanks all.

- BlueDev
[/quote]

This topic is closed to new replies.

Advertisement