十年
Delphi创建OCX控件非常的方便,但IE调用时弹出的安全认证非常麻烦,有时OCX也不需要界面,IE调用时需要隐藏,非常不方便。在DELPHI中创建OCX实现安全接口和创建事件中修改部分代码
实现安全接口 继承:IObjectSafety 重载方法: function GetInterfaceSafetyOptions(const IID: TIID; pdwSupportedOptions, //安全接口 pdwEnabledOptions: PDWORD): HResult; stdcall; function SetInterfaceSafetyOptions(const IID: TIID; dwOptionSetMask, dwEnabledOptions: DWORD): HResult; stdcall; function TZhddMsg.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^ := INTERFACESAFE_FOR_UNTRUSTED_CALLER or INTERFACESAFE_FOR_UNTRUSTED_DATA; end else begin pdwSupportedOptions^ := 0; pdwEnabledOptions^ := 0; end; end; function TZhddMsg.SetInterfaceSafetyOptions(const IID: TIID; dwOptionSetMask, dwEnabledOptions: DWORD): HResult; var Unk: IUnknown; begin Result := QueryInterface(IID, Unk); if Result <> S_OK then Exit; end; 无界面: initialization TActiveFormFactory.Create( ComServer, TActiveFormControl, TZhddMsg, Class_ZhddMsg, 1, '', OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL, //OLEMISC_INVISIBLEATRUNTIME or OLEMISC_ACTSLIKELABEL, //隐藏主界面 tmApartment); end.