Windows Registry


The Windows Registry is a centralized database that stores settings, options, and preferences on Windows computers. REALbasic provides a class, called RegistryItem, to access the Registry.

The Registry organizes the data into a hierarchy. There are five basic categories of data in the Windows Registry, known as Hives for some reason (as one who has plenty of food allergies, the word "hives" has negative connotations for me). They are as follows:

HKEY_CLASSES_ROOT

This is where file extensions are mapped to applications and where ActiveX controls are registered. The file extensions are important because that is how Windows knows which application to open when you double-click a file. If you muck about in this part, you can quite maliciously set things up so that double-clicking just about any file opens up your particular application. Don't do that. As a matter of fact, it's considered good practice to check with the user before making any kind of change to the application/file-type association.

HKEY_CURRENT_USER

This represents the currently logged in user's preferences. If you are saving preferences for an application that you have created, you would want to create a RegistryItem at a path similar to this:

HKEY_CURRENT_USER\Software\MyApp\Preferences


HKEY_LOCAL_MACHINE

Systemwide configuration goes here. You might include data that is applicable to all users of your application. In other words, if you had some application-specific configuration data you wanted to save that did not vary by user, you'd save it here.

HKEY_USERS

This contains the underlying data from which HKEY_CURRENT_USER is derived. This is not an area that is commonly modified and I would avoid it unless I really knew what I was doing.

HKEY_CURRENT_CONFIG

This hive stores data for the current hardware profile. Much like HKEY_USERS, I wouldn't do anything here unless I absolutely knew what I was doing.

The Windows Registry is hierarchical and is organized into folders, much like the file system is. The Hives are the root folders and each subfolder can contain a series of key/value pairs. Also, just like you can refer to real files and folders using a path, you can do the same with RegistryItems. All RegistryItems have a path, and the Hive is the first element in a RegistryItem Path. The data in each key/value pair is also of a particular type. The types are outlined in Table 4.14

Table 4.14. Windows Registry Data Types

Value Type

Windows Designation

Integer Value

Not supported

 

-1

String, Expandable String

REG_SZ and REG_EXPAND_SZ

0

DWORD

REG_DWORD

1

Binary String

REG_BINARY

2

String array (Or multistring)

REG_MULTI_SZ

3


Strings are just strings. Expandable strings are strings that contain variables that need to be expanded, or filled in. In Windows, environment variables are signified by being enclosed with %. Expanding the string will replace the value of the variable with its true value. This means that this:

%TEMP%\SomeFile.txt


Would be expanded to this:

C:\WINDOWS\TEMP\SomeFile.txt


You cannot assign an Expandable String to the Registry, but you can receive the value of it, already expanded.

You can receive the value of a Multi-String, but you cannot set it. The string is delimited by a character with the ASCII value of zero. You can use the standard Split function to convert it into an Array.

myArray = Split(someMultiString, Chr(0))


Binary strings and DWORDs both represent binary data. DWORDs represent numeric data, whereas binary strings can represent anything. In other words, if you wanted to store a small graphic file, you would store it as a binary string, but if you wanted to store the fact that the application has been used 100 times, you'd use a DWORD.

Later on in the chapter, I will create a Preferences class for the RSSReader project that uses the RegistryItem class.




REALbasic Cross-Platform Application Development
REALbasic Cross-Platform Application Development
ISBN: 0672328135
EAN: 2147483647
Year: 2004
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net