1,问题描述:写了个OCX,在本地静态html文件里加载,双击用IE打开,能够正常加载OCX控件,调用其方法也正常,把测试的html文件放入apache目录,通过IE 敲入localhost访问也正常,但是部署到服务器上,通过客户端PC访问服务器IP的方式,却不能加载OCX,其方法也调用不了。
2,问题解决,上网查了下,以及根据以往的对接经验,做如下设置:
1)在IE里把web服务的IP加入受信任站点:
2)还是在受信任站点的界面里设置“自定义级别”为“低”:
这样应该就能通过ip访问服务器页面时加载ocx控件了。
3,额外的解决:
后来查到ocx要实现安全接口:OCX控件在HTML中调用时提示:【SCRIPT3: 找不到成员。】
我试了下,添加了IObjectSafety接口后,不需要设置IE也可以正常加载OCX并调用其方法。
====================================================================================
转载自 https://blog.csdn.net/laironggui/article/details/79422118
写了一个ocx控件,测试OK后,嵌入到HTML中使用,发现死活调取不了方法,很纳闷!
搜索了方法,说只要设置一下IE浏览器的权限即可:启用“对未标记为安全执行脚本的activex控件初始化并执行脚本”。
这个方法不是不行,而是要求每一个用户都去设置这个权限,显然不合适。
于是乎继续研究方法,终于找到了解决方案!
那就是:实现ActiveX组件的IObjectSafety接口,并且返回脚本安全。
具体来说,就是在h和cpp中加入以下代码:
1、OCXTestCtrl.h
//////////////////////////////////////////////////////////////////////////
// ActiveX控件安全初始化:实现ISafeObject接口
//////////////////////////////////////////////////////////////////////////
//ISafeObject
DECLARE_INTERFACE_MAP()
BEGIN_INTERFACE_PART(ObjSafe, IObjectSafety)
STDMETHOD_(HRESULT, GetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
);
STDMETHOD_(HRESULT, SetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions
);
END_INTERFACE_PART(ObjSafe);
//ISafeObject
2、OCXTestCtrl.cpp
//////////////////////////////////////////////////////////////////////////
// ActiveX控件安全初始化:实现ISafeObject接口
//////////////////////////////////////////////////////////////////////////
// Interface map for IObjectSafety
BEGIN_INTERFACE_MAP( COCXTestCtrl, COleControl )
INTERFACE_PART(COCXTestCtrl, IID_IObjectSafety, ObjSafe)
END_INTERFACE_MAP()
// IObjectSafety member functions
// Delegate AddRef, Release, QueryInterface
ULONG FAR EXPORT COCXTestCtrl::XObjSafe::AddRef()
{
METHOD_PROLOGUE(COCXTestCtrl, ObjSafe)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT COCXTestCtrl::XObjSafe::Release()
{
METHOD_PROLOGUE(COCXTestCtrl, ObjSafe)
return pThis->ExternalRelease();
}
HRESULT FAR EXPORT COCXTestCtrl::XObjSafe::QueryInterface(
REFIID iid, void FAR* FAR* ppvObj)
{
METHOD_PROLOGUE(COCXTestCtrl, ObjSafe)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
const DWORD dwSupportedBits =
INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
const DWORD dwNotSupportedBits = ~ dwSupportedBits;
//.............................................................................
// CStopLiteCtrl::XObjSafe::GetInterfaceSafetyOptions
// Allows container to query what interfaces are safe for what. We're
// optimizing significantly by ignoring which interface the caller is
// asking for.
HRESULT STDMETHODCALLTYPE
COCXTestCtrl::XObjSafe::GetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE(COCXTestCtrl, ObjSafe)
HRESULT retval = ResultFromScode(S_OK);
// does interface exist?
IUnknown FAR* punkInterface;
retval = pThis->ExternalQueryInterface(&riid,
(void * *)&punkInterface);
if (retval != E_NOINTERFACE) { // interface exists
punkInterface->Release(); // release it--just checking!
}
// we support both kinds of safety and have always both set,
// regardless of interface
*pdwSupportedOptions = *pdwEnabledOptions = dwSupportedBits;
return retval; // E_NOINTERFACE if QI failed
}
/////////////////////////////////////////////////////////////////////////////
// CStopLiteCtrl::XObjSafe::SetInterfaceSafetyOptions
// Since we're always safe, this is a no-brainer--but we do check to make
// sure the interface requested exists and that the options we're asked to
// set exist and are set on (we don't support unsafe mode).
HRESULT STDMETHODCALLTYPE
COCXTestCtrl::XObjSafe::SetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions)
{
METHOD_PROLOGUE(COCXTestCtrl, ObjSafe)
// does interface exist?
IUnknown FAR* punkInterface;
pThis->ExternalQueryInterface(&riid, (void * *)&punkInterface);
if (punkInterface) { // interface exists
punkInterface->Release(); // release it--just checking!
}
else { // interface doesn't exist
return ResultFromScode(E_NOINTERFACE);
}
// can't set bits we don't support
if (dwOptionSetMask & dwNotSupportedBits) {
return ResultFromScode(E_FAIL);
}
// can't set bits we do support to zero
dwEnabledOptions &= dwSupportedBits;
// (we already know there are no extra bits in mask )
if ((dwOptionSetMask & dwEnabledOptions) !=
dwOptionSetMask) {
return ResultFromScode(E_FAIL);
}
// don't need to change anything since we're always safe
return ResultFromScode(S_OK);
}
//////////////////////////////////////////////////////////////////////////
实例截图: