wr960204代码速度很快,采纳为答案!顺便修正一下!
uses
ComObj, ComServ, ActiveX;
{$R *.dfm}
function LoadTypeLibrary(const ModuleName: string): ITypeLib;
begin
OleCheck(LoadTypeLib(PWideChar(WideString(ModuleName)), Result));
end;
//根据类型库遍历出DLL中所有COCLASS的GUID,然后到注册表中看看有没有注册
Function ComHasRegisted(ComDLLName : String):Boolean;
var
TL : ITypeLib;
TypeInfo : ITypeInfo;
I:Integer;
ptypeAttrib : PTypeAttr;
typeAttrib : TYPEATTR;
KeyName : String;
ClassKey : HKEY;
begin
Result := False;
TL := LoadTypeLibrary(ComDLLName);
if TL = nil then
Exit;
for I := 0 to TL.GetTypeInfoCount - 1 do
begin
TL.GetTypeInfo(I, TypeInfo);
TypeInfo.GetTypeAttr(ptypeAttrib);
typeAttrib := ptypeAttrib^;
TypeInfo.ReleaseTypeAttr(ptypeAttrib);
if typeAttrib.typekind = TKIND_COCLASS then
begin
KeyName := 'CLSID/' + GUIDToString(typeAttrib.guid);
if RegOpenKey(HKEY_CLASSES_ROOT,
PChar(KeyName),
ClassKey) = ERROR_SUCCESS then
begin
Result := True;
Exit;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not OpenDialog1.Execute() then
Exit;
if ComHasRegisted(OpenDialog1.FileName) then
begin
ShowMessage('注册了!');
end else
ShowMessage('未注册!');
end;
end.