Coder's Guild Mailing List

MFC registry

Posted by Fox on 2000-10-20

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.