Poggle: Working with the Registry

The program will access the registry in two places in Poggle's Application class. One is the ExitInstance() where the menu options the user has picked are stored until the next session. The other is the InitInstance() (of course). It goes without saying that the standard warnings about working in the registry are in full force even when doing entry change programmatically.
Not only that, for more involved programs, the programmer has to keep the registry structure for the program in mind. Will the structure need updating when the program changes? (I am doing this for my Concentration program, and it is an iron-casted pain.) How will changes in the registry (from the user or otherwise) be handled?

Step 15: I put the following after the program's initialization executes LoadStdProfileSettings(0), which loads the .INI file stuff.

Using the RegCreateKeyEx() function is a two-fer operation. If the key does not exit, the operation creates it. Otherwise, the key is opened for further work. The key returned from this function can be used in the following functions to point to the proper registry entry.
For the root registry key of the program the following options were used;
The Registry Key to be worked on was the hive, HKEY_CURRENT_USER (wait for it) to keep the user's choices personnal.
The SubKey used is "Software\\Your Company\\Poggle". (Thought I was going to work on the hive root, didn't you.) Note the escaped slashes.
The registry option used was REG_OPTION_NON_VOLATILE to keep the entries between sessions.
The Security option used was KEY_ALL_ACCESS. Used appropriately, this parameter allows the programmer to tailor the program's functionality to the best (lowest) security settings needed. Done wrong, only the Administrator will be able to run the program.

The returned value from this function is asserted to be equal to ERROR_SUCCESS.
The results value (what went on) is asserted NOT to be NULL.

If the results value is REG_CREATED_NEW_KEY then the program's session values for size and colour cycles need to be created, via RegSetValueEx().
Otherwise the values for this sessions can be retrieved with RegQueryValueEx(). Mind the results value of NULL (error from the registry key creation/open) should be handled as well.

Step 16: In the ExitInstance() function all that needs to be done is to use the RegSetValueEx() function to enter the session values before the program exits.

No comments: