怎样列出WINDOWS系统中的所有ACTIVEX 类型库,包括DLL和OCX(100分)

  • 主题发起人 主题发起人 alen
  • 开始时间 开始时间
A

alen

Unregistered / Unconfirmed
GUEST, unregistred user!
如DELPHI中的Import ActiveX Control。
 
这个东西应该是在WINDOWS注册表中去检查的吧!
你看 如果一个acrivex没有注册的话
delphi的import activex control也列不出来的

我自己也没做过,只是瞎猜一下
 
无私奉献源代码,主要是分析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;
 
这个源码是封装在一个类( http://www.techvanguards.com 可以下载 )
里面的,照抄是编译不了的,只是给你思路而已
 
接受答案了.
 
后退
顶部