Develop in Delphi 2010 (or compatible), the following two functions:
Function ExportRegistryKey(const Root : HKEY; const Key: String; var Output : TStringList; const QuitOnError : Boolean = True) : Integer;
Function ExportRegistryEntry(const Root : HKEY; const Key: String; const EntryName : String; var Output : TStringList) : Integer;
ExportRegistryKey saves the contents of the given registry key, including any possible sub-keys, to the given Output StringList in a format of a Windows .reg file. If QuitOnError = False, the function saves all the possible data to the Output list, ignoring any possible errors that occur while iterating and reading the registry.
ExportRegistryEntry saves the name and value of the given registry entry to the given Output stringlist using the Windows .reg file format.
The functions must be implemented using Windows API (you are not allowed to use the TRegistry or the Registry unit of Delphi), and must support the saving of all the known registry data types. If you need to write any helper functions, feel free to do so.
In a case of error, the functions must return an error code. If the function runs without any error, it must return 0. The functions can assume that given Output Stringlist exists and that it already contains the necessary header information of the .reg file. However, the functions must not assume that the given Output Stringlist is empty. It may (or may not) contain data added there by previous ExportRegistryKey/Entry function calls.
You can use Windows [url removed, login to view]'s File > Export feature for examples how .reg files are generated. If QuitOnError is True, the function quits in a case of error in reading the data. If one would call e.g. ExportRegistryKey on registry key "hkey_local_machine\software\foobar" and use RegEdit's File > Export ... feature on the same key, the resulting .reg file's content should match the Output StringList generated by the ExportRegistryKey call.