C++ question...

4 replies [Last post]
COSCstudent
COSCstudent's picture
Offline
Apprentice
Joined: 2009/05/14

Okay, so let me try to explain what I am trying to do without giving away a secret. I am trying to test what the value of HKEY is (i.e. is it HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, etc) and then do some things based on what it is. Here is a sample of my main CPP file (those of you who know code):

int main()
{
HKEY theKey = HKEY_LOCAL_MACHINE;
HKEY thisKey = HKEY_CURRENT_USER;
string someKey = "Software\\Policies\\Microsoft\\Windows\\DriverSearching";
string randomKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
int userInput;
string holder;

RegistryWrapper hklmKey( theKey );

hklmKey.getValues( someKey );
}

I know that I can do this if they are all still in the same CPP file, but I am separating the CPP files to help make my code more readable. Basically, when I declare an object of the class RegistryWrapper, I am passing the "value" of the HKEY to a private variable in my .h file in this project:

(in the .h file, just a peek)

class RegistryWrapper
{
public:
string checkLocations();
// Functions and variables which are public.
private:
HKEY hKey;
// Other functions and variables which are private.
}

This way, I can have the object hold the value of it's main key and I can access it at any time. The problem that I am running into is that I want to run this particular piece of code, but I don't know how to check the "value" of the HKEY:

string RegistryWrapper::checkLocations()
{
if( hKey == HKEY_LOCAL_MACHINE )
{
// Do something in relation to the HKLM key.
}
else if( hKey == HKEY_CURRENT_USER )
{
// Do something in relation to the HKCU key.
}
else
// Quit function because you aren't using either of the correct keys.
}

Basically, you would think that the if() function would work, but when I go to test it, it will skip both because apparently I am not testing hKey with the correct parameters. I have tried outputting the value of hKey to the command line using cout, but it just returns 80000002 for HKLM and 80000001 for HKCU. If anyone could help me out with this, I would greatly appreciate it. I have been trying to get past this roadblock for the past week and can't seem to get past it. I am not asking for anyone to correct my code because I am aware that this is not perfect syntax, I am just asking for some help on what I can use to test what the "value" of hKey is. Thanks in advance!

"You can never excel at something you don't truly enjoy."
- Jack Nicklaus