Windows/MFC
CRegKey
aucd29
2013. 10. 2. 18:07
Link : http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20154056.html
Hi Folks,
trying to work out how to use CRegKey - i don;t understand the process for the Open() function...
here's what i can figure out so far:
HKEY m_hKey; // create a HKEY
CRegKey key; // create a CRegKey
char *szValue; // pointer to receive the
DWORD *pdwCount; // to get the buffer length
CString keyVal = "defaultvalue";
if( key.Open(m_hKey, "HKEY_LOCAL_MACHINE\\Software\\GSAT\\QuotaMan", KEY_READ) == ERROR_SUCCESS) // open the key
{
if(key.QueryValue( szValue, "keyVal", pdwCount )) // see if there is a value
{
keyVal=szValue; // if there is, set the variable
Log( "Got keyVal = " + szValue ); // just a function to write output to a text file
}
key.Close();
}
this all compiles ok, but i get a link error error LNK2001 (unresolved external symboL) on all three member functions of CRegKey - i assume that i have the arguments mucked up..?
thanks for any suggestion,
cheers, Mike.
Link : http://www.netalive.org/codersguild/posts/2088.shtml
I need a little help with using the registry in MFC C++. Every time I run it, it
creates the keys called "Friction", "BOS", etc., within the "Software" key. I want
it to create a subkey in "Software" called "Smiley Life 2.0" and put those entries
in that key. But it keeps skipping that step and putting the stuff in "Software".
Why?
What am I doing wrong that's making the program not create a subkey in
"Software" and putting all the values in that key?
unsigned long NEW;
CRegKey SmileyKey;
SmileyKey.Open(HKEY_CURRENT_USER, "Software");
SmileyKey.Create((HKEY)"Software", "Smiley Life 2.0", REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &NEW);
if(NEW == REG_CREATED_NEW_KEY)
{
SmileyKey.Open((HKEY)"Software", "Smiley Life 2.0");
SmileyKey.SetKeyValue("Friction", "15", "default");
SmileyKey.SetKeyValue("StartingPop", "10", "default");
SmileyKey.SetKeyValue("MaxPop", "40", "default");
SmileyKey.SetKeyValue("TTR", "45", "default");
SmileyKey.SetKeyValue("NTE", "3", "default");
SmileyKey.SetKeyValue("MaxAge", "0", "default");
SmileyKey.SetKeyValue("Sunlight", "0", "default");
SmileyKey.SetKeyValue("BOS", "0", "default");
SmileyKey.Close();
}
//this block sets the environment values to the defaults just in case
Friction = 15;
StartingPop = 10;
MaxPop = 40;
TTR = 45;
NTE = 3;
MaxAge = 0; //implies unlimited age
Sunlight = 0;
BOS = 0;
SmileyKey.Open(HKEY_CURRENT_USER, "Software");
SmileyKey.Open((HKEY)"Software", "Smiley Life 2.0");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "Friction");
SmileyKey.QueryValue((unsigned long &)Friction, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "StartingPop");
SmileyKey.QueryValue((unsigned long &)StartingPop, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "MaxPop");
SmileyKey.QueryValue((unsigned long &)MaxPop, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "TTR");
SmileyKey.QueryValue((unsigned long &)TTR, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "NTE");
SmileyKey.QueryValue((unsigned long &)NTE, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "MaxAge");
SmileyKey.QueryValue((unsigned long &)MaxAge, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "Sunlight");
SmileyKey.QueryValue((unsigned long &)Sunlight, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "BOS");
SmileyKey.QueryValue((unsigned long &)BOS, "default");
please send help!
PS-- thanks for the info on programming schools. I will go for a technical
education....all I gotta do is find a place to go.
Hi Folks,
trying to work out how to use CRegKey - i don;t understand the process for the Open() function...
here's what i can figure out so far:
HKEY m_hKey; // create a HKEY
CRegKey key; // create a CRegKey
char *szValue; // pointer to receive the
DWORD *pdwCount; // to get the buffer length
CString keyVal = "defaultvalue";
if( key.Open(m_hKey, "HKEY_LOCAL_MACHINE\\Software\\GSAT\\QuotaMan", KEY_READ) == ERROR_SUCCESS) // open the key
{
if(key.QueryValue( szValue, "keyVal", pdwCount )) // see if there is a value
{
keyVal=szValue; // if there is, set the variable
Log( "Got keyVal = " + szValue ); // just a function to write output to a text file
}
key.Close();
}
this all compiles ok, but i get a link error error LNK2001 (unresolved external symboL) on all three member functions of CRegKey - i assume that i have the arguments mucked up..?
thanks for any suggestion,
cheers, Mike.
Link : http://www.netalive.org/codersguild/posts/2088.shtml
I need a little help with using the registry in MFC C++. Every time I run it, it
creates the keys called "Friction", "BOS", etc., within the "Software" key. I want
it to create a subkey in "Software" called "Smiley Life 2.0" and put those entries
in that key. But it keeps skipping that step and putting the stuff in "Software".
Why?
What am I doing wrong that's making the program not create a subkey in
"Software" and putting all the values in that key?
unsigned long NEW;
CRegKey SmileyKey;
SmileyKey.Open(HKEY_CURRENT_USER, "Software");
SmileyKey.Create((HKEY)"Software", "Smiley Life 2.0", REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &NEW);
if(NEW == REG_CREATED_NEW_KEY)
{
SmileyKey.Open((HKEY)"Software", "Smiley Life 2.0");
SmileyKey.SetKeyValue("Friction", "15", "default");
SmileyKey.SetKeyValue("StartingPop", "10", "default");
SmileyKey.SetKeyValue("MaxPop", "40", "default");
SmileyKey.SetKeyValue("TTR", "45", "default");
SmileyKey.SetKeyValue("NTE", "3", "default");
SmileyKey.SetKeyValue("MaxAge", "0", "default");
SmileyKey.SetKeyValue("Sunlight", "0", "default");
SmileyKey.SetKeyValue("BOS", "0", "default");
SmileyKey.Close();
}
//this block sets the environment values to the defaults just in case
Friction = 15;
StartingPop = 10;
MaxPop = 40;
TTR = 45;
NTE = 3;
MaxAge = 0; //implies unlimited age
Sunlight = 0;
BOS = 0;
SmileyKey.Open(HKEY_CURRENT_USER, "Software");
SmileyKey.Open((HKEY)"Software", "Smiley Life 2.0");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "Friction");
SmileyKey.QueryValue((unsigned long &)Friction, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "StartingPop");
SmileyKey.QueryValue((unsigned long &)StartingPop, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "MaxPop");
SmileyKey.QueryValue((unsigned long &)MaxPop, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "TTR");
SmileyKey.QueryValue((unsigned long &)TTR, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "NTE");
SmileyKey.QueryValue((unsigned long &)NTE, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "MaxAge");
SmileyKey.QueryValue((unsigned long &)MaxAge, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "Sunlight");
SmileyKey.QueryValue((unsigned long &)Sunlight, "default");
SmileyKey.Open((HKEY)"Smiley Life 2.0", "BOS");
SmileyKey.QueryValue((unsigned long &)BOS, "default");
please send help!
PS-- thanks for the info on programming schools. I will go for a technical
education....all I gotta do is find a place to go.