Archived

This topic is now archived and is closed to further replies.

Krysole

prob with RegEnumValue returning error

Recommended Posts

Krysole    140
hi...heres my prob i load a registry key for my application and then read out how many values the key has, followed by a for loop that calls RegEnumValue for each value to determine it's type and then RegQueryValueEx to actually get the value. the prob is that after loading one variable the functions appear to stop working properly? by returning a ERROR_MORE_DATA error return code. i can't figure out what the problem is, i learn't this stuff from the documentation so maybe there's something i missed...any help is appreciated...here's a rather large but complete snippet of the code with the error
int dpInitRegistry(void)
{
	HKEY key;
	unsigned long values, valmax, datamax, type, isize = sizeof(int);
	char *name, *data;
	int idata;
	string sname;

	// Open registry key

	if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\diskplay\\regexp", 0, 
	KEY_ALL_ACCESS, &key)) {
		return 0;
	}

	// Query key for values

	if (RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, &values, 
	&valmax, &datamax, NULL, NULL)) {
		RegCloseKey(key);
		Debug("RegQueryInfoKey returned an error");
		return 0;
	}
	if (!values) {
		RegCloseKey(key);
		Debug("Apparently there are no values present; success returned anyway");
		return 1;
	}

	// allocate c-style string memory

	if (!valmax || !datamax) {
		RegCloseKey(key);
		Debug("Apparently all registry saved data has length of zero?");
		return 0;
	}
	name = new char[valmax + 1];
	if (!name) {
		RegCloseKey(key);
		return 0;
	}
	datamax++;
	data = new char[datamax];
	if (!data) {
		delete[] data;
		RegCloseKey(key);
		return 0;
	}

	// import all values held within the key

	for (unsigned int i = 0; i < values; ++i)
	{
		LONG retVal;
		if (retVal = RegEnumValue(key, i, name, &valmax, NULL, &type, NULL, NULL)) {
			continue;
		}
		if (type == REG_SZ) {
			if (RegQueryValueEx(key, name, NULL, NULL, 
			reinterpret_cast<LPBYTE>(data), &datamax)) {
				continue;
			}
			sname = name;
			sname.erase(sname.begin()); // erase 's' prefix

			g_state->SetStr(name, data);
			continue;
		}
		if (type == REG_DWORD) {
			if (RegQueryValueEx(key, name, NULL, NULL, 
			reinterpret_cast<LPBYTE>(&idata), &isize)) {
				continue;
			}
			sname = name;
			sname.erase(sname.begin()); // erase 'i' prefix

			g_state->SetInt(name, idata);
			continue;
		}
	}

	RegCloseKey(key);
	return 1;
}
 
the code on my machine reaches the continue after RegEnumValue and if i ignore the error the other funcs also return the same error... all i need is for someone to tell me why it's returning the error and perhaps even a solution to it. thx < krysole | krysollix > sleep, caffeine for the weak minded edit: swapped code tag for source tag

Share this post


Link to post
Share on other sites