The Win32 API provides a set of functions to access data stored in the Registry. Before it can add data to the Registry, an application must create or open a key. An application always refers to the key as a subkey of a currently open key, using the RegOpenKey or RegOpenKeyEx function to open a key and the RegCreateKey or RegCreateKeyEx function to create a key.
The RegCloseKey function closes a key and writes the data it contains into the Registry. The data cannot be written to the Registry before the function returns because it might take several seconds for the cache to be flushed to the hard disk. If the data must be written to the hard disk immediately, the application can use the RegFlushKey function. (Because this function uses many system resources, you should call it only when absolutely necessary.)