实现IObjectSafety即可,示例代码参照如下:
Delphi(Pascal) code
unit UpdaterXImpl;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, LesUpdater_TLB, StdVcl, Windows;
type
TUpdaterX = class(TAutoObject,IObjectSafety, IUpdaterX)
private
FObjectSafetyFlags: DWORD;
protected
procedure Start; safecall;
{ IObjectSafety }
function GetInterfaceSafetyOptions(const IID: TIID; pdwSupportedOptions,
pdwEnabledOptions: PDWORD): HResult; virtual; stdcall;
function SetInterfaceSafetyOptions(const IID: TIID; dwOptionSetMask,
dwEnabledOptions: DWORD): HResult; virtual; stdcall;
end;
implementation
uses ComServ, Main;
function TUpdaterX.GetInterfaceSafetyOptions(const IID: TIID;
pdwSupportedOptions, pdwEnabledOptions: PDWORD): HResult;
var
Unk: IUnknown;
begin
if (pdwSupportedOptions = nil) or (pdwEnabledOptions = nil) then
begin
Result := E_POINTER;
Exit;
end;
Result := QueryInterface(IID, Unk);
if Result = S_OK then
begin
pdwSupportedOptions^ := INTERFACESAFE_FOR_UNTRUSTED_CALLER or
INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwEnabledOptions^ := FObjectSafetyFlags and
(INTERFACESAFE_FOR_UNTRUSTED_CALLER or INTERFACESAFE_FOR_UNTRUSTED_DATA);
end
else begin
pdwSupportedOptions^ := 0;
pdwEnabledOptions^ := 0;
end;
end;
function TUpdaterX.SetInterfaceSafetyOptions(const IID: TIID; dwOptionSetMask,
dwEnabledOptions: DWORD): HResult;
var
Unk: IUnknown;
begin
Result := QueryInterface(IID, Unk);
if Result <> S_OK then Exit;
FObjectSafetyFlags := dwEnabledOptions and dwOptionSetMask;
end;