描述:
我现在刚在学习做actixex控件,现在遇到一个关于在web上面发布的问题急切希望得到高手的指点。我参考资料通过vs2003工具通过工程向导创建了一个mfc下的ActiveX控件,取名aaa,任何代码未添加。然后想试下该控件在web中的发布效果。于是我通过工具将该直接生成的控件插入到网页中取名default1.html,并和aaa.ocx文件一起放置在iis目录下。然后我通过regsvr32 /u 命令将该控件反注册。然后将我的ie的安全设置关于actixeX控件的设置全部开启。然后输入http://localhost/default1.html可以正常显示该控件。但是当我输入本机的ip地址或者在客户机上运行的时候总是出现一个红X。和前面输入http://localhost/default1.html相比会少一个提示是否允许交互。我通过vs2003里面的工具查看到该控件也在客户机上面安装成功了。调试了几天这个问题始终不能解决。请教csdn里面的高手能帮下我,不知道该问题到底出在哪里?
解决方案1:
什么红叉, 提示什么信息, 问题描述的清楚一点,
应该是安全接口 问题, 中加这些就可以了(适合mfc)
.h文件中加:
BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD __RPC_FAR *pdwSupportedOptions, DWORD __RPC_FAR *pdwEnabledOptions);
STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);
END_INTERFACE_PART(ObjectSafety)
cpp中:
BEGIN_INTERFACE_MAP(your ctrl, COleControl)
INTERFACE_PART(your ctrl, IID_IObjectSafety, ObjectSafety)
END_INTERFACE_MAP()
STDMETHODIMP your ctrl::XObjectSafety::GetInterfaceSafetyOptions(
REFIID riid,
DWORD __RPC_FAR *pdwSupportedOptions,
DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE_EX(your ctrl, ObjectSafety)
if (!pdwSupportedOptions || !pdwEnabledOptions)
{
return E_POINTER;
}
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
*pdwEnabledOptions = 0;
if (NULL == pThis->GetInterface(&riid))
{
TRACE(_T("Requested interface is not supported.\n"));
return E_NOINTERFACE;
}
// What interface is being checked out anyhow?
OLECHAR szGUID[39];
int i = StringFromGUID2(riid, szGUID, 39);
if (riid == IID_IDispatch)
{
// Client wants to know if object is safe for scripting
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
// Those are the persistence interfaces COleControl derived controls support
// as indicated in AFXCTL.H
// Client wants to know if object is safe for initializing from persistent data
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK;
}
else
{
// Find out what interface this is, and decide what options to enable
TRACE(_T("We didn't account for the safety of this interface, and it's one we support...\n"));
return E_NOINTERFACE;
}
}
STDMETHODIMP your ctrl::XObjectSafety::SetInterfaceSafetyOptions(
REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions)
{
METHOD_PROLOGUE_EX(your ctrl, ObjectSafety)
OLECHAR szGUID[39];
// What is this interface anyway?
// We can do a quick lookup in the registry under HKEY_CLASSES_ROOT\Interface
int i = StringFromGUID2(riid, szGUID, 39);
if (0 == dwOptionSetMask && 0 == dwEnabledOptions)
{
// the control certainly supports NO requests through the specified interface
// so it's safe to return S_OK even if the interface isn't supported.
return S_OK;
}
// Do we support the specified interface?
if (NULL == pThis->GetInterface(&riid))
{
TRACE1("%s is not support.\n", szGUID);
return E_FAIL;
}
if (riid == IID_IDispatch)
{
TRACE(_T("Client asking if it's safe to call through IDispatch.\n"));
TRACE(_T("In other words, is the control safe for scripting?\n"));
if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions)
{
return S_OK;
}
else
{
return E_FAIL;
}
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
TRACE(_T("Client asking if it's safe to call through IPersist*.\n"));
TRACE(_T("In other words, is the control safe for initializing from persistent data?\n"));
if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)
{
return NOERROR;
}
else
{
return E_FAIL;
}
}
else
{
TRACE1("We didn't account for the safety of %s, and it's one we support...\n", szGUID);
return E_FAIL;
}
}
STDMETHODIMP_(ULONG) your ctrl::XObjectSafety::AddRef()
{
METHOD_PROLOGUE_EX_(your ctrl, ObjectSafety)
return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) your ctrl::XObjectSafety::Release()
{
METHOD_PROLOGUE_EX_(your ctrl, ObjectSafety)
return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP your ctrl::XObjectSafety::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(your ctrl, ObjectSafety)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
你的组件要实现IObjectSafety接口,具体加上下面两行:
class CXXX:public IObjectSafetyImpl<CFactory, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
COM_INTERFACE_ENTRY(IObjectSafety)
也就是你除了将安全属性设置成允许下载末签名的组件,还要设置一下允许下载末标记为安全的组件,否则你可以向上