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