注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

斗天堂

douzsh还活着

 
 
 

日志

 
 

activex控件在IE中弹出安全警告的解决办法zz  

2008-05-05 17:41:27|  分类: C语言基础 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

//在控件头文件中加入:

#include <objsafe.h>

 DECLARE_INTERFACE_MAP()

 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(CVP2PCtrl, COleControl)

  INTERFACE_PART(CVP2PCtrl, IID_IObjectSafety, ObjectSafety)

END_INTERFACE_MAP()

// Implementation of IObjectSafety

STDMETHODIMP CVP2PCtrl::XObjectSafety::GetInterfaceSafetyOptions(

   REFIID riid,

   DWORD __RPC_FAR *pdwSupportedOptions,

   DWORD __RPC_FAR *pdwEnabledOptions)

{

 METHOD_PROLOGUE_EX(CVP2PCtrl, ObjectSafety)

 if (!pdwSupportedOptions || !pdwEnabledOptions)

 {

  return E_POINTER;

 }

 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;

 *pdwEnabledOptions = 0;

 if (NULL == pThis->GetInterface(&riid))

 {

  TRACE("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("We didn't account for the safety of this interface, and it's one we support...\n");

  return E_NOINTERFACE;

 } 

}

STDMETHODIMP CVP2PCtrl::XObjectSafety::SetInterfaceSafetyOptions(

  REFIID riid,

  DWORD dwOptionSetMask,

  DWORD dwEnabledOptions)

{

 METHOD_PROLOGUE_EX(CVP2PCtrl, 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("Client asking if it's safe to call through IDispatch.\n");

  TRACE("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("Client asking if it's safe to call through IPersist*.\n");

  TRACE("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) CVP2PCtrl::XObjectSafety::AddRef()

{

 METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)

 return (ULONG)pThis->ExternalAddRef();

}

STDMETHODIMP_(ULONG) CVP2PCtrl::XObjectSafety::Release()

{

 METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)

 return (ULONG)pThis->ExternalRelease();

}

STDMETHODIMP CVP2PCtrl::XObjectSafety::QueryInterface(

 REFIID iid, LPVOID* ppvObj)

{

 METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)

 return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);

}

//OK!不会再探出那个倒霉的对话框了~~~

//代码是啥意思?不知道,别问我~反正加了就不会探出就是了。其中CVP2PCtrl全部要换成你的控件的类名~ 

  评论这张
 
阅读(538)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017