January 18th, 2008

Why do registry keys have a default value?

In addition to all the named values you can create underneath a registry key with the RegSetValueEx function, there is also the so-called default value which you obtain by passing NULL or a pointer to a null string as the lpValue. This default value is also the value set and retrieved when you call RegSetValue and RegQueryValue. What’s the deal with this default value? The original 16-bit registry didn’t have named values. All it had were keys, and associated with each key was a single piece of data: a string. The functions that operated on this data were RegSetValue and RegQueryValue, which explains why those functions (1) don’t have a lpValue parameter and (2) set and retrieve only string data. Because back in the 16-bit world, that’s all you had. In the conversion to Win32, the registry gained new capabilities, such as storing data in formats beyond simple strings, and storing multiple pieces of data under a single key, using a name to distinguish them. What used to be called simply “the value of a registry key” (for since there was only one, there was no need to give it a name) now goes by the special name the default value: It’s the value whose name is null.

There’s nothing particularly special about the default value aside from its unusual name. A named value need not exist, and if it exists, the data type could be anything. Similarly, the default value need not exist, and its type can be anything. At this point, it’s just a value with a strange name.

Topics
History

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.