无私奉献源代码,主要是分析HKEY_CLASSES_ROOT/TypeLib下面的GUID而已。
procedure TRegTypeLibs.ReadRegistry;
procedure ReadTypeLib (reg: TRegistry; const sLibId, sLibVersion: string);
var
sSubkey, sLibDescription, sLibFile: string;
lstSubkeys: TStringList;
rtl: TRegTypeLib;
i: integer;
begin
Assert (reg <> nil);
lstSubKeys := TStringList.Create;
try
with reg do
begin
if not (OpenKey ('TypeLib/' + sLibId + '/' + sLibVersion, FALSE)) then Exit;
sLibDescription := ReadString ('');
{ load subkeys and parse out for numeric with a win32 subkey }
GetKeyNames (lstSubKeys);
CloseKey;
for i := 0 to lstSubKeys.Count - 1 do
begin
sSubkey := lstSubkeys ;
if (sSubKey = '') then Continue;
if not (sSubkey [1] in ['0'..'9']) then Continue;
{ win32 }
if not (OpenKey ('TypeLib/' + sLibId + '/' + sLibVersion + '/' + sSubKey + '/win32', FALSE)) then Continue;
sLibFile := ReadString ('');
CloseKey;
//if not (FileExists (sLibFile)) then Continue;
{ add item }
rtl := TRegTypeLib.Create;
rtl.Filename := sLibFile;
rtl.Description := Format ('%s (version %s)', [sLibDescription, sLibVersion]);
FItems.Add (rtl);
Break;
end; { for }
end; { with }
finally
lstSubKeys.Free;
end; { finally }
end;
var
reg: TRegistry;
i, j: integer;
lstTypeLibs, lstVersions: TStringList;
begin
{ browse through HKCR/TypeLib }
Clear;
reg := TRegistry.Create;
lstTypeLibs := TStringList.Create;
lstVersions := TStringList.Create;
try
with reg do
begin
RootKey := HKEY_CLASSES_ROOT;
if not (OpenKey ('TypeLib', FALSE)) then Exit;
{ enumerate }
GetKeyNames (lstTypeLibs);
CloseKey;
{ each lib is like this:
LibId
Version No
No?
Win32
}
for i := 0 to lstTypeLibs.Count - 1 do
begin
if not (OpenKey ('TypeLib/' + lstTypeLibs , FALSE)) then Continue;
{ load versions }
GetKeyNames (lstVersions);
CloseKey;
for j := 0 to lstVersions.Count - 1 do
ReadTypeLib (reg, lstTypeLibs , lstVersions [j]);
end; { for }
end; { with }
Sort;
finally
lstVersions.Free;
lstTypeLibs.Free;
reg.Free;
end; { finally }
end;