不同版本的GUID不同,你可以指定用那个版本的const SMSDOMNotInstalled = 'Microsoft MSXML 4.0 or upper is not installed.'; // msxml parser 4.0 ProgID_FreeThreadedDOMDocument40 = 'Msxml2.FreeThreadedDOMDocument.4.0'; // msxml parser 6.0 ProgID_FreeThreadedDOMDocument60 = 'Msxml2.FreeThreadedDOMDocument.6.0';type EMSXMLDomException = class(Exception);function TryObjectCreateFromProgID(const ProgIDList: array of PWideChar): IUnknown; overload; var I: Integer; FClsID: TGUID; Status: HResult; begin for I := Low(ProgIDList) to High(ProgIDList) do if Succeeded(CLSIDFromProgID(ProgIDList[I], FClsID)) then begin Status := CoCreateInstance(FClsID, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IUnknown, Result); if Status = S_OK then Exit; end; end;function CreateDOMDocument: IXMLDOMDocument; begin Result := TryObjectCreateFromProgID([ProgID_FreeThreadedDOMDocument60, ProgID_FreeThreadedDOMDocument40]) as IXMLDOMDocument; if not Assigned(Result) then raise EMSXMLDomException.Create(SMSDOMNotInstalled); end;
程序运动时,按下F12让程序断下来
然后按Ctrl+Alt+M,就可以看到程序引用到哪些DLL了。
SMSDOMNotInstalled = 'Microsoft MSXML 4.0 or upper is not installed.';
// msxml parser 4.0
ProgID_FreeThreadedDOMDocument40 = 'Msxml2.FreeThreadedDOMDocument.4.0';
// msxml parser 6.0
ProgID_FreeThreadedDOMDocument60 = 'Msxml2.FreeThreadedDOMDocument.6.0';type
EMSXMLDomException = class(Exception);function TryObjectCreateFromProgID(const ProgIDList: array of PWideChar): IUnknown; overload;
var
I: Integer;
FClsID: TGUID;
Status: HResult;
begin
for I := Low(ProgIDList) to High(ProgIDList) do
if Succeeded(CLSIDFromProgID(ProgIDList[I], FClsID)) then
begin
Status := CoCreateInstance(FClsID, nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IUnknown, Result);
if Status = S_OK then Exit;
end;
end;function CreateDOMDocument: IXMLDOMDocument;
begin
Result := TryObjectCreateFromProgID([ProgID_FreeThreadedDOMDocument60, ProgID_FreeThreadedDOMDocument40]) as IXMLDOMDocument;
if not Assigned(Result) then
raise EMSXMLDomException.Create(SMSDOMNotInstalled);
end;