Mega Code Archive

 
Categories / Delphi / System
 

Obtain a list of class names in a COM ocxdll

Title: Obtain a list of class names in a COM ocx/dll Question: You may wish to obtain a list of class names/interfaces exported in a COM dll or ocx. It is not practical to search the registry for these class names based on a file name. This will allow you to obtain the list programmatically. A samle usage would be to build a dialog which allows the user to select a file (ocx or dll) and see a list of available classes, of which they could select one to use as a plugin. Answer: function GetClassNames(AFileName: String): TStrings; var TypeLib: ITypeLib; Name: WideString; i: integer; begin Result := TStringList.Create; OleCheck(LoadTypeLib(PWideChar(WideString(AFileName)), TypeLib)); if assigned(TypeLib) then begin for i := 0 to (TypeLib.GetTypeInfoCount - 1) do begin TypeLib.GetDocumentation(i, @Name, nil, nil, nil); Result.Add(Name); end; end; end;