****高手都路过来看一看吧!有关罗列COM+下的东东****(50分)

  • 主题发起人 主题发起人 lovelovelily
  • 开始时间 开始时间
L

lovelovelily

Unregistered / Unconfirmed
GUEST, unregistred user!
var
CataColl:TCOMAdminCatalogCollection;
CataObj:TCOMAdminCatalogObject;
COMADminCata:TCOMAdminCatalog;
i:integer;
k,j:integer;
begin
COMADminCata := TCOMAdminCatalog.Create(self);
CataColl := COMADminCata.GetCollection('Applications');
CataColl.Populate;
for i:= 0 to CataColl.Count-2 do
begin
CataObj:=CataColl.Get_Item(i);
self.ListBox1.Items.Add(CataObj.Name);
if CataObj.Name='OK' then
begin
****************
****************
end;
end;
COMADminCata.Free;
end;
请问如何在发现OK COM+服务后,在继续发现OK下的组件名,接口名,以及接口下的方法,方法的参数,谢谢!
 
这个也是个方法,不过有现成的例子列举接口下的组件,方法,参数,只要引用ItypeInfo就可以了。
单元activeX.pas
ITypeInfo2 = interface(ITypeInfo)
['{00020412-0000-0000-C000-000000000046}']
function GetTypeKind(out pTypeKind: TTypeKind): HResult;
stdcall;
function GetTypeFlags(out pTypeFlags: LongInt): HResult;
stdcall;
function GetFuncIndexOfMemId(memid: TMemberID;
invKind: TInvokeKind;
out pFuncIndex: UINT): HResult;
stdcall;
function GetVarIndexOfMemId(memid: TMemberID;
out pVarIndex: UINT): HResult;
stdcall;
function GetCustData(guid: TGUID;
out pVarVal: OleVariant): HResult;
stdcall;
function GetFuncCustData(index: UINT;
guid: TGUID;
out pVarVal: OleVariant): HResult;
stdcall;
function GetParamCustData(indexFunc, indexParam: UINT;
guid: TGUID;
out pVarVal: OleVariant): HResult;
stdcall;
function GetVarCustData(index: UINT;
guid: TGUID;
out pVarVal: OleVariant): HResult;
stdcall;
function GetImplTypeCustData(index: UINT;
guid: TGUID;
out pVarVal: OleVariant): HResult;
stdcall;
function GetDocumentation2(memid: TMemberID;
lcid: TLCID;
pbstrHelpString: PWideString;
pdwHelpStringContext: PDWORD;
pbstrHelpStringDll: PWideString): HResult;
stdcall;
function GetAllCustData(out pCustData: TCustData): HResult;
stdcall;
function GetAllFuncCustData(index: UINT;
out pCustData: TCustData): HResult;
stdcall;
function GetAllParamCustData(indexFunc, indexParam: UINT;
out pCustData: TCustData): HResult;
stdcall;
function GetAllVarCustData(index: UINT;
out pCustData: TCustData): HResult;
stdcall;
function GetAllImplTypeCustData(index: UINT;
out pCustData: TCustData): HResult;
stdcall;
end;
ITypeInfo = interface(IUnknown)
['{00020401-0000-0000-C000-000000000046}']
function GetTypeAttr(out ptypeattr: PTypeAttr): HResult;
stdcall;
function GetTypeComp(out tcomp: ITypeComp): HResult;
stdcall;
function GetFuncDesc(index: Integer;
out pfuncdesc: PFuncDesc): HResult;
stdcall;
function GetVarDesc(index: Integer;
out pvardesc: PVarDesc): HResult;
stdcall;
function GetNames(memid: TMemberID;
rgbstrNames: PBStrList;
cMaxNames: Integer;
out cNames: Integer): HResult;
stdcall;
function GetRefTypeOfImplType(index: Integer;
out reftype: HRefType): HResult;
stdcall;
function GetImplTypeFlags(index: Integer;
out impltypeflags: Integer): HResult;
stdcall;
function GetIDsOfNames(rgpszNames: POleStrList;
cNames: Integer;
rgmemid: PMemberIDList): HResult;
stdcall;
function Invoke(pvInstance: Pointer;
memid: TMemberID;
flags: Word;
var dispParams: TDispParams;
varResult: PVariant;
excepInfo: PExcepInfo;
argErr: PInteger): HResult;
stdcall;
function GetDocumentation(memid: TMemberID;
pbstrName: PWideString;
pbstrDocString: PWideString;
pdwHelpContext: PLongint;
pbstrHelpFile: PWideString): HResult;
stdcall;
function GetDllEntry(memid: TMemberID;
invkind: TInvokeKind;
bstrDllName, bstrName: PWideString;
wOrdinal: PWord): HResult;
stdcall;
function GetRefTypeInfo(reftype: HRefType;
out tinfo: ITypeInfo): HResult;
stdcall;
function AddressOfMember(memid: TMemberID;
invkind: TInvokeKind;
out ppv: Pointer): HResult;
stdcall;
function CreateInstance(const unkOuter: IUnknown;
const iid: TIID;
out vObj): HResult;
stdcall;
function GetMops(memid: TMemberID;
out bstrMops: WideString): HResult;
stdcall;
function GetContainingTypeLib(out tlib: ITypeLib;
out pindex: Integer): HResult;
stdcall;
procedure ReleaseTypeAttr(ptypeattr: PTypeAttr);
stdcall;
procedure ReleaseFuncDesc(pfuncdesc: PFuncDesc);
stdcall;
procedure ReleaseVarDesc(pvardesc: PVarDesc);
stdcall;
end;
GetDocumentation可以取得这些指针.
例子代码略。。
 
只能列举出接口及方法,不能列举出方法的参数,因为这和DLL一样,参数是不公开的,除非你有对应的文档.MSDN里都有示例代码的,不过都是C++和VB的
 
不,接口的参数是公开的,本身接口是纯虚的,参数可以取得。本身就有保护作用。
接口是接口,DLL的参数是DLL的参数。
 
有空,我会贴出代码的。。。。郁闷。
 
谢谢,最好有列出接口,和接口下的方法的代码?谢谢
 
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, ExtCtrls, ActiveX;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
treeTI: TTreeView;
StatusBar1: TStatusBar;
FileMenu: TMenuItem;
FileExit1: TMenuItem;
FileOpen1: TMenuItem;
OpenDialog1: TOpenDialog;
procedure FileExit1Click(Sender: TObject);
procedure FileOpen1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FLib: ITypeLib;
FEnumRoot: TTreeNode;
FDispatchRoot: TTreeNode;
FInterfaceRoot: TTreeNode;
FCoClassRoot: TTreeNode;
FUnknownRoot: TTreeNode;
procedure LoadTypeLibrary;
procedure LoadEnum(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
procedure LoadInterface(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
procedure LoadCoClass(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
uses
ComObj;
{$R *.DFM}
procedure TForm1.FileExit1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.LoadEnum(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
var
TypeLibNode: TTreeNode;
AName: WideString;
ADocString: WideString;
AHelpContext: LongInt;
ValuesNode: TTreeNode;
ValueNode: TTreeNode;
ValueIndex: Integer;
VarDesc: PVarDesc;
begin
TypeInfo.GetDocumentation(-1, @AName, @ADocString, @AHelpContext,
nil);
TypeLibNode := treeTI.Items.AddChild(FEnumRoot, AName);
treeTI.Items.AddChild(TypeLibNode, 'Version ' +
IntToStr(TypeAttr.wMajorVerNum) + '.' +
IntToStr(TypeAttr.wMinorVerNum));
if ADocString <> '' then
treeTI.Items.AddChild(TypeLibNode, 'Help string: ' + ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(TypeLibNode, 'Help context: ' +
IntToStr(AHelpContext));
ValuesNode := treeTI.Items.AddChild(TypeLibNode, 'Values');
for ValueIndex := 0 to TypeAttr.cVars - 1do
begin
TypeInfo.GetVarDesc(ValueIndex, VarDesc);
try
TypeInfo.GetDocumentation(VarDesc.memid, @AName, @ADocString,
@AHelpContext, nil);
ValueNode := treeTI.Items.AddChild(ValuesNode, AName);
if ADocString <> '' then
treeTI.Items.AddChild(ValueNode, 'Help string: ' +
ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(ValueNode, 'Help context: ' +
IntToStr(AHelpContext));
finally
TypeInfo.ReleaseVarDesc(VarDesc);
end;
end;
end;

procedure TForm1.LoadInterface(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
var
TypeLibNode: TTreeNode;
AName: WideString;
ADocString: WideString;
AHelpContext: LongInt;
FunctionsNode: TTreeNode;
FunctionNode: TTreeNode;
FuncIndex: Integer;
FuncDesc: PFuncDesc;
ParametersNode: TTreeNode;
ParamIndex: Integer;
Names: PBStrList;
cNames: Integer;
begin
TypeInfo.GetDocumentation(-1, @AName, @ADocString, @AHelpContext,
nil);
if TypeAttr.typeKind = TKIND_DISPATCH then
TypeLibNode := treeTI.Items.AddChild(FDispatchRoot, AName)
else
TypeLibNode := treeTI.Items.AddChild(FInterfaceRoot, AName);
treeTI.Items.AddChild(TypeLibNode, GUIDToString(TypeAttr.GUID));
treeTI.Items.AddChild(TypeLibNode, 'Version ' +
IntToStr(TypeAttr.wMajorVerNum) + '.' +
IntToStr(TypeAttr.wMinorVerNum));
if ADocString <> '' then
treeTI.Items.AddChild(TypeLibNode, 'Help string: ' + ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(TypeLibNode, 'Help context: ' +
IntToStr(AHelpContext));
New(Names);
try
// load functions
FunctionsNode := treeTI.Items.AddChild(TypeLibNode, 'Functions');
for FuncIndex := 0 to TypeAttr.cFuncs - 1do
begin
TypeInfo.GetFuncDesc(FuncIndex, FuncDesc);
try
TypeInfo.GetDocumentation(FuncDesc.memid, @AName,
@ADocString, @AHelpContext, nil);
FunctionNode := treeTI.Items.AddChild(FunctionsNode, AName);
if ADocString <> '' then
treeTI.Items.AddChild(FunctionNode, 'Help string: ' +
ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(FunctionNode, 'Help context: ' +
IntToStr(AHelpContext));
if FuncDesc.cParams > 0 then
begin
// load parameters
ParametersNode := treeTI.Items.AddChild(FunctionNode,
'Parameters');
TypeInfo.GetNames(FuncDesc.memid, Names, sizeof(TBStrList),
cNames);
// Skip Names[0] - it's the function name
for ParamIndex := 1 to FuncDesc.cParamsdo
treeTI.Items.AddChild(ParametersNode, Names[ParamIndex]);
end;
finally
TypeInfo.ReleaseFuncDesc(FuncDesc);
end;
end;
finally
Dispose(Names);
end;
end;

procedure TForm1.LoadCoClass(TypeInfo: ITypeInfo;
TypeAttr: PTypeAttr);
var
TypeLibNode: TTreeNode;
AName: WideString;
ADocString: WideString;
AHelpContext: LongInt;
FunctionsNode: TTreeNode;
FuncIndex: Integer;
RefType: Cardinal;
TypeInfo2: ITypeInfo;
begin
TypeInfo.GetDocumentation(-1, @AName, @ADocString, @AHelpContext,
nil);
TypeLibNode := treeTI.Items.AddChild(FCoClassRoot, AName);
treeTI.Items.AddChild(TypeLibNode, GUIDToString(TypeAttr.GUID));
if ADocString <> '' then
treeTI.Items.AddChild(TypeLibNode, 'Help string: ' + ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(TypeLibNode, 'Help context: ' +
IntToStr(AHelpContext));
FunctionsNode := treeTI.Items.AddChild(TypeLibNode, 'Implements');
for FuncIndex := 0 to TypeAttr.cImplTypes - 1do
begin
TypeInfo.GetRefTypeOfImplType(FuncIndex, RefType);
TypeInfo.GetRefTypeInfo(RefType, TypeInfo2);
TypeInfo2.GetDocumentation(-1, @AName, nil, nil, nil);
treeTI.Items.AddChild(FunctionsNode, AName);
end;
end;

procedure TForm1.LoadTypeLibrary;
var
LibAttr: PTLibAttr;
TypeInfo: ITypeInfo;
TypeLibIndex: Integer;
AName: WideString;
ADocString: WideString;
AHelpContext: LongInt;
AHelpFile: WideString;
TypeAttr: PTypeAttr;
RootNode: TTreeNode;
begin
Screen.Cursor := crHourglass;
try
treeTI.Items.begin
Update;
try
treeTI.Items.Clear;
FLib.GetDocumentation(-1, @AName, @ADocString, @AHelpContext,
@AHelpFile);
// Load help information
RootNode := treeTI.Items.AddChild(nil, AName);
// GUID, version, LCID
OleCheck(FLib.GetLibAttr(LibAttr));
try
treeTI.Items.AddChild(RootNode, GUIDToString(LibAttr.GUID));
treeTI.Items.AddChild(RootNode, 'Version ' +
IntToStr(LibAttr.wMajorVerNum) + '.' +
IntToStr(LibAttr.wMinorVerNum));
treeTI.Items.AddChild(RootNode, 'LCID: ' +
IntToStr(LibAttr.lcid));
finally
FLib.ReleaseTLibAttr(LibAttr);
end;

// Help information
if ADocString <> '' then
treeTI.Items.AddChild(RootNode, 'Help string: ' + ADocString);
if AHelpContext <> 0 then
treeTI.Items.AddChild(RootNode, 'Help context: ' +
IntToStr(AHelpContext));
if AHelpFile <> '' then
treeTI.Items.AddChild(RootNode, 'Help file: ' + AHelpFile);
// Set no nodes for various types
FEnumRoot := treeTI.Items.AddChild(RootNode, 'Enum');
FDispatchRoot := treeTI.Items.AddChild(RootNode, 'Dispatch');
FInterfaceRoot := treeTI.Items.AddChild(RootNode, 'Interface');
FCoClassRoot := treeTI.Items.AddChild(RootNode, 'CoClass');
FUnknownRoot := treeTI.Items.AddChild(RootNode, 'Unknown');
for TypeLibIndex := 0 to FLib.GetTypeInfoCount - 1do
begin
FLib.GetTypeInfo(TypeLibIndex, TypeInfo);
OleCheck(TypeInfo.GetTypeAttr(TypeAttr));
try
case TypeAttr.typeKind of
TKIND_ENUM:
LoadEnum(TypeInfo, TypeAttr);
TKIND_DISPATCH,
TKIND_INTERFACE:
LoadInterface(TypeInfo, TypeAttr);
TKIND_COCLASS:
LoadCoClass(TypeInfo, TypeAttr);
else
treeTI.Items.AddChild(FUnknownRoot,
'Unrecognized type: ' + IntToStr(TypeAttr.typeKind));
end;
finally
TypeInfo.ReleaseTypeAttr(TypeAttr);
end;
end;

RootNode.Expand(False);
finally
treeTI.Items.EndUpdate;
end;
finally
Screen.Cursor := crDefault;
end;
end;

procedure TForm1.FileOpen1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
OleCheck(LoadTypeLib(PWideChar(WideString(OpenDialog1.FileName)),
FLib));
LoadTypeLibrary;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if ParamCount = 1 then
begin
try
OleCheck(LoadTypeLib(PWideChar(WideString(ParamStr(1))),
FLib));
LoadTypeLibrary;
except
on E: Exceptiondo
begin
ShowMessage(E.Message);
Application.Terminate;
end;
end;
end;
end;

end.
------------------
object Form1: TForm1
Left = 247
Top = 87
Width = 362
Height = 385
Caption = 'Type Information Viewer'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object treeTI: TTreeView
Left = 0
Top = 0
Width = 354
Height = 320
Align = alClient
Indent = 19
TabOrder = 0
end
object StatusBar1: TStatusBar
Left = 0
Top = 320
Width = 354
Height = 19
Panels = <>
SimplePanel = False
end
object MainMenu1: TMainMenu
Left = 312
Top = 8
object FileMenu: TMenuItem
Caption = '&File'
object FileOpen1: TMenuItem
Caption = '&Open...'
ShortCut = 16463
OnClick = FileOpen1Click
end
object FileExit1: TMenuItem
Caption = 'E&xit'
OnClick = FileExit1Click
end
end
end
object OpenDialog1: TOpenDialog
DefaultExt = 'exe'
Filter =
'Executable files (*.exe)|*.exe|Dynamic link libraries (*.dll)|*.' +
'dll|Type libraries (*.tlb;*.olb)|*.tlb;*.olb'
Options = [ofHideReadOnly, ofNoChangeDir, ofPathMustExist, ofFileMustExist, ofEnableSizing]
Left = 272
Top = 8
end
end
 
后退
顶部