Hi,
As I'm new to C++, but not to programming, I tried to start simple by reading off value from the registry. I'm talking about standard values such as the processor's name.
I made a little function which checked how many processors the user has, that works fine. But I would then like to give the user the names of the processors. But I'm having trouble with the RegQueryValueEx function from Windows.h.
I use this function to retreive the name:
char * processor(double index)
{
HKEY key;
LONG succeeded;
succeeded = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"+(char)index, NULL, KEY_READ, &key);
if (succeeded == ERROR_SUCCESS)
{
char *value = ;
DWORD value_size = sizeof(value);
while (RegQueryValueEx(key, "ProcessorNameString", NULL, NULL, (BYTE *)value, &value_size) == ERROR_MORE_DATA)
{
value = new char[1];
value_size = sizeof(value);
}
RegCloseKey(key);
return value;
}
else
{
return "FAILED";
}
}
There is no error, but an even more annoying problem: my computer has 2 processors, so the code has to return this:
processor(0) == "Intel(R) Core(TM)2 Duo CPU E7300 @ 2.66GHz"
processor(1) == "Intel(R) Core(TM)2 Duo CPU E7300 @ 2.66GHz"
But instead, is returns this:
processor(0) == ""
processor(1) == "FAILED"
Which isn't the same :P.
I was hoping that one of you knows what I do wrong. If so, please answer simple, as I do not know a lot about C++.
Ragoune