呵呵,Connection控件找到是一回事,能调用又是一回事.还有待实践的检验.
我是先找到了下面这个函数,就是Connection控件用来罗列Server列表用的.
procedure GetMIDASAppServerList(List: TStringList;
const RegCheck: string);
var
EnumGUID: IEnumGUID;
Fetched: Cardinal;
Guid: TGUID;
Rslt: HResult;
CatInfo: ICatInformation;
I, BufSize: Integer;
ClassIDKey: HKey;
S: string;
Buffer: array[0..255] of Char;
begin
List.Clear;
Rslt := CoCreateInstance(CLSID_StdComponentCategoryMgr, nil,
CLSCTX_INPROC_SERVER, ICatInformation, CatInfo);
if Succeeded(Rslt) then
begin
//关键是这句**************************************************************
[red]OleCheck(CatInfo.EnumClassesOfCategories(1, @CATID_MIDASAppServer, 0, nil, EnumGUID));[/red]
while EnumGUID.Next(1, Guid, Fetched) = S_OKdo
begin
if RegCheck <> '' then
begin
S := SClsid + GuidToString(Guid) + '/';
if GetRegStringValue(S, RegCheck) <> SFlagOn then
continue;
end;
List.Add(ClassIDToProgID(Guid));
end;
end else
begin
if RegOpenKey(HKEY_CLASSES_ROOT, 'CLSID', ClassIDKey) <> 0 then
try
I := 0;
while RegEnumKey(ClassIDKey, I, Buffer, SizeOf(Buffer)) = 0do
begin
S := Format(SCatImplKey, [Buffer, GUIDToString(CATID_MIDASAppServer)]);
if RegQueryValue(ClassIDKey, PChar(S), nil, BufSize) = 0 then
if RegCheck <> '' then
begin
BufSize := 256;
SetLength(S, BufSize);
if RegQueryValueEx(ClassIDKey, PChar(RegCheck), nil, nil,
PByte(PChar(S)), @BufSize) = ERROR_SUCCESS then
SetLength(S, BufSize - 1) else
S := '';
if GetRegStringValue(S, RegCheck) <> SFlagOn then
continue;
end;
List.Add(ClassIDToProgID(StringToGUID(Buffer)));
Inc(I);
end;
finally
RegCloseKey(ClassIDKey);
end;
end;
end;