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 else
107 {
108 return E_FAIL;
109 }
110 }
111 else
112 {
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全部要换成你的控件的类名
OCX控件避免弹出安全警告的类的更多相关文章
- ocx控件避免弹出警告的类--2
本文与 OCX控件避免弹出安全警告的类 http://www.cnblogs.com/lidabo/archive/2013/03/26/2981852.html 有些类似,只不过增加了几行代码(红色 ...
- 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog
[源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...
- 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
[源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...
- 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
[源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...
- 控件(弹出类): ToolTip, Popup, PopupMenu
示例1.ToolTip 的示例Controls/FlyoutControl/ToolTipDemo.xaml <Page x:Class="Windows10.Controls.Fly ...
- 小程序中点击input控件键盘弹出时placeholder文字上移
最近做的一个小程序项目中,出现了点击input控件键盘弹出时placeholder文字上移,刚开始以为是软键盘弹出布局上移问题是传说中典型的fixed 软键盘顶起问题,因此采纳了网上搜到的" ...
- 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
1.FlyoutBase(基类) 的示例Controls/FlyoutControl/FlyoutBaseDemo.xaml <Page x:Class="Windows10.Cont ...
- 在指定控件位置弹出popup window
先看效果图 黄色的就是弹出的popup window 首先自定义一个view用来显示,文件名为layout_my_view.xml <?xml version="1.0" e ...
- 问题-PopupMenu是哪个控件调用弹出的?
相关资料: http://bbs.csdn.net/topics/310195683 问题现象:今天有朋友问我个简单的问题,在多个Edit上弹出菜单,怎么判断是哪个Edit调用的.我想了想这个我还真不 ...
随机推荐
- Seinfeld(杭电3351)
Seinfeld Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- Mybatis分页插件-PageHelper的使用
转载:http://blog.csdn.net/u012728960/article/details/50791343 Mybatis分页插件-PageHelper的使用 怎样配置mybatis这里就 ...
- Debian Customer PPA RFC (by quqi99)
作者:张华 发表于:2016-01-13版权声明:能够随意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) Pre ...
- mysql 执行sql文件的方法
http://philos.iteye.com/blog/162051 实战代码: #mysql导入mysql -um4n -p01D060A476642BA8335B832AC5B211F22 ...
- nightwatch.js - scroll until element is visible
.getLocationInView() Determine an element's location on the screen once it has been scrolled into vi ...
- python datetime获取几分钟、小时、天之前的时间
import datetime print ((datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d ...
- android等待旋转圆圈动画
先创建一个动画的xml文件例如以下 <? xml version="1.0" encoding="utf-8"?> <animation-li ...
- 电源滤波电容在PCB中正确的布线方法!
电源滤波电容在PCB中正确的布线方法! 错误的电源滤波电容布线方法. 1.很多人朋友在设计的时候喜欢加宽这个电源的走,这个是一个很好的方法,但是他们如果一不小心就会忽略电容的布线. 下面的电容布线看起 ...
- Codeforces Round #267 (Div. 2) B. Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...
- python3短信接口使用
import http.client from urllib import parse host = "106.ihuyi.com" sms_send_uri = "/w ...