OCX控件避免弹出安全警告的类

1.要加一个头文件:
         #include <objsafe.h>

2.在控件头文件中加入:

1 DECLARE_INTERFACE_MAP()2     BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)3         STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD __RPC_FAR *pdwSupportedOptions, DWORD __RPC_FAR *pdwEnabledOptions);4         STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);5     END_INTERFACE_PART(ObjectSafety)

3.在控件的CPP文件中加入:

  1 BEGIN_INTERFACE_MAP(CVP2PCtrl, COleControl)  2   INTERFACE_PART(CVP2PCtrl, IID_IObjectSafety, ObjectSafety)  3 END_INTERFACE_MAP()  4 // Implementation of IObjectSafety  5 STDMETHODIMP CVP2PCtrl::XObjectSafety::GetInterfaceSafetyOptions(  6    REFIID riid,   7    DWORD __RPC_FAR *pdwSupportedOptions,   8    DWORD __RPC_FAR *pdwEnabledOptions)  9 { 10  METHOD_PROLOGUE_EX(CVP2PCtrl, ObjectSafety) 11  12  if (!pdwSupportedOptions || !pdwEnabledOptions) 13  { 14  return E_POINTER; 15  } 16  17  *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; 18  *pdwEnabledOptions = 0; 19  20  if (NULL == pThis->GetInterface(&riid)) 21  { 22   TRACE("Requested interface is not supported.\n"); 23  return E_NOINTERFACE; 24  } 25  26  // What interface is being checked out anyhow? 27  OLECHAR szGUID[39]; 28  int i = StringFromGUID2(riid, szGUID, 39); 29  30  if (riid == IID_IDispatch) 31  { 32  // Client wants to know if object is safe for scripting 33  *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER; 34  return S_OK; 35  } 36  else if (riid == IID_IPersistPropertyBag  37  || riid == IID_IPersistStreamInit 38  || riid == IID_IPersistStorage 39  || riid == IID_IPersistMemory) 40  { 41  // Those are the persistence interfaces COleControl derived controls support 42  // as indicated in AFXCTL.H 43  // Client wants to know if object is safe for initializing from persistent data 44  *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA; 45  return S_OK; 46  } 47  else 48  { 49  // Find out what interface this is, and decide what options to enable 50   TRACE("We didn't account for the safety of this interface, and it's one we support...\n"); 51  return E_NOINTERFACE; 52  }  53 } 54  55 STDMETHODIMP CVP2PCtrl::XObjectSafety::SetInterfaceSafetyOptions( 56   REFIID riid,  57   DWORD dwOptionSetMask,  58   DWORD dwEnabledOptions) 59 { 60  METHOD_PROLOGUE_EX(CVP2PCtrl, ObjectSafety) 61  62  OLECHAR szGUID[39]; 63  // What is this interface anyway? 64  // We can do a quick lookup in the registry under HKEY_CLASSES_ROOT\Interface 65  int i = StringFromGUID2(riid, szGUID, 39); 66  67  if (0 == dwOptionSetMask && 0 == dwEnabledOptions) 68  { 69  // the control certainly supports NO requests through the specified interface 70  // so it's safe to return S_OK even if the interface isn't supported. 71  return S_OK; 72  } 73  74  // Do we support the specified interface? 75  if (NULL == pThis->GetInterface(&riid)) 76  { 77   TRACE1("%s is not support.\n", szGUID); 78  return E_FAIL; 79  } 80  81  if (riid == IID_IDispatch) 82  { 83   TRACE("Client asking if it's safe to call through IDispatch.\n"); 84   TRACE("In other words, is the control safe for scripting?\n"); 85  if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions) 86   { 87  return S_OK; 88   } 89  else 90   { 91  return E_FAIL; 92   } 93  } 94  else if (riid == IID_IPersistPropertyBag  95  || riid == IID_IPersistStreamInit 96  || riid == IID_IPersistStorage 97  || riid == IID_IPersistMemory) 98  { 99   TRACE("Client asking if it's safe to call through IPersist*.\n");100   TRACE("In other words, is the control safe for initializing from persistent data?\n");101 102  if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)103   {104  return NOERROR;105   }106  else107   {108  return E_FAIL;109   }110  }111  else112  {113   TRACE1("We didn't account for the safety of %s, and it's one we support...\n", szGUID);114  return E_FAIL;115  }116 }117 118 STDMETHODIMP_(ULONG) CVP2PCtrl::XObjectSafety::AddRef()119 {120  METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)121  return (ULONG)pThis->ExternalAddRef();122 }123 124 STDMETHODIMP_(ULONG) CVP2PCtrl::XObjectSafety::Release()125 {126  METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)127  return (ULONG)pThis->ExternalRelease();128 }

//OK!不会再弹出那个“与ActiveX控件交互不安全“的对话框了~~~

//其中CVP2PCtrl全部要换成你的控件的类名

 

 from:http://www.cnblogs.com/rushoooooo/archive/2011/06/22/2087544.html

时间: 2024-11-02 09:52:20

OCX控件避免弹出安全警告的类的相关文章

ocx控件避免弹出警告的类--2

本文与 OCX控件避免弹出安全警告的类 http://www.cnblogs.com/lidabo/archive/2013/03/26/2981852.html 有些类似,只不过增加了几行代码(红色标注)   1.要加一个头文件:         #include <objsafe.h>2.在控件头文件中加入: ////////////////////////////////////////////////////////////////////////// //安全接口实现 DECLARE

VB中抑制控件的弹出菜单

在VB的某些控件如文本框(TEXTBOX).组合框(COMBOBOX)等上单击鼠标右键都会有缺省的弹出菜单,这些缺省弹出菜单,在某些情况下我们并不需要或者根据实际情况需要使用自己的弹出菜单,那么如何抑制控件的弹出菜单呢?我们需要检测控件的鼠标右键单击消息,然后什么事也不做或者使用自己的弹出菜单,这需要编写一个钩子函数来完成.下面以抑制文本框的弹出菜单为例说明实现方法. 为窗体添加一个模块,在模块中编写钩子函数: 首先声明使用的API函数及常量, Declare Function CallWind

金山界面库,tab控件怎么弹出对话框?

问题描述 金山界面库,tab控件怎么弹出对话框? 我自己用向导建的项目 就是在tab控件那里实现弹出对话框 解决方案 自己DoModal等创建对话框就可以弹出了

easyui关于window控件如何弹出如何遮住导航菜单栏

问题描述 easyui关于window控件如何弹出如何遮住导航菜单栏 最近项目中使用easyui,用到它的组建导航栏,菜单,布局,还有window弹出窗口.页面的布局如下:![图片说明](http://img.ask.csdn.net/upload/201506/04/1433390271_271778.jpg) 在中间部分另一个页面,点击"新增按钮" 就会弹出window控件,但是弹出之后显示的范围在中间页面中而不是整个浏览器页面中,就该怎么解决. 解决方案 window控件是居于浏

背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

原文:背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹出类) ToolTip Popup PopupMenu 示例1.ToolTip 的示例Controls/FlyoutControl/ToolTipDemo.xaml <Page

背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

原文:背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹出类) MessageDialog ContentDialog 示例1.MessageDialog 的示例Controls/FlyoutControl/Message

背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

原文:背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹出类) FlyoutBase Flyout MenuFlyout 示例1.FlyoutBase(基类) 的示例Controls/FlyoutControl/F

如何使用PopupWin控件同时弹出2个提醒

问题描述 如何使用PopupWin控件同时弹出2个提醒,给出2个链接到不同页面 解决方案 解决方案二:自己顶解决方案三:没试过,帮顶解决方案四:没概念,帮你定定解决方案五:是一个第三方控件吗?解决方案六:<SCRIPTlanguage=JavaScript1.2>functionopenWindowBack(){varpopUpWin2=open("第二个页面.html","popUpWin2","width=1,height=1,top=40

改造asp.net日历控件为弹出式日期选择控件和GridView呈现长文本字段的两个技巧

asp.net中自带了一个非常不错的日历控件,但在其呈现方式上还是稍有欠缺.现在我们用一个小技巧,可以轻松创建一个弹出式日期.自此你再也不用去网上找那个带了很多脚本代码的JS制作的弹出式日期控件了. 实现,方式很简单:只需在页面中加入一点Javascript和一些CSS,就可以制作一个简单的弹出式日期选择器. 其中,.aspx代码如下: <head id="Head1" runat="server"> <title>无标题页</titl