博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MFC工程环境下,制作Activex ocx取消IE浏览器的安全提示
阅读量:2394 次
发布时间:2019-05-10

本文共 9310 字,大约阅读时间需要 31 分钟。

在xxxCtrl.h(xxx为项目名)头文件中的 #pragma once的 下一行 添加

//-------添加---------------

//取消ie的安全提示
#include "objsafe.h"
//---------添加完----------------------------

并在头文件类中的声明部分声明(和CxxxCtrl()构造函数同一个地方)

//----------增加  取消ie的安全提示-----=----    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);    //---------添加完----------------------------

在 CPP实现文件

BOOL Cmax200Ctrl::Cmax200CtrlFactory::UpdateRegistry(BOOL bRegister)函数后面添加如下

注意下面的代码要替换Cmax200Ctrl到你自己的类名

//--------添加-------------------//取消ie的安全提示/ // Interface map for IObjectSafety	BEGIN_INTERFACE_MAP( Cmax200Ctrl, COleControl ) 		INTERFACE_PART(Cmax200Ctrl, IID_IObjectSafety, ObjSafe) 	END_INTERFACE_MAP()/ // IObjectSafety member functions// Delegate AddRef, Release, QueryInterfaceULONG FAR EXPORT Cmax200Ctrl::XObjSafe::AddRef() { 	METHOD_PROLOGUE(Cmax200Ctrl, ObjSafe) 		return pThis->ExternalAddRef(); }ULONG FAR EXPORT Cmax200Ctrl::XObjSafe::Release() { 	METHOD_PROLOGUE(Cmax200Ctrl, ObjSafe) 		return pThis->ExternalRelease(); }HRESULT FAR EXPORT Cmax200Ctrl::XObjSafe::QueryInterface( 	REFIID iid, void FAR* FAR* ppvObj) { 	METHOD_PROLOGUE(Cmax200Ctrl, 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 Cmax200Ctrl::XObjSafe::GetInterfaceSafetyOptions( 	/* [in] */ REFIID riid, 	/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions, 	/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions) { 	METHOD_PROLOGUE(Cmax200Ctrl, 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 	Cmax200Ctrl::XObjSafe::SetInterfaceSafetyOptions( 	/* [in] */ REFIID riid, 	/* [in] */ DWORD dwOptionSetMask, 	/* [in] */ DWORD dwEnabledOptions) { 	METHOD_PROLOGUE(Cmax200Ctrl, 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); }//-------------添加结束--------------------

/

微软官网实例

推荐使用这个
Implement the CreateComponentCategory and RegisterCLSIDInCategory helper functions by adding the following cathelp.h and cathelp.cpp files to your project.
  1. Cathelp.h

    #include "comcat.h"      // Helper function to create a component category and associated      // description      HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);      // Helper function to register a CLSID as belonging to a component      // category      HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);

    Cathelp.cpp

    #include "comcat.h"      // Helper function to create a component category and associated      // description      HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)      {         ICatRegister* pcr = NULL ;         HRESULT hr = S_OK ;         hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,                               NULL,                               CLSCTX_INPROC_SERVER,                               IID_ICatRegister,                               (void**)&pcr);         if (FAILED(hr))            return hr;         // Make sure the HKCR\Component Categories\{..catid...}         // key is registered         CATEGORYINFO catinfo;         catinfo.catid = catid;         catinfo.lcid = 0x0409 ; // english         // Make sure the provided description is not too long.         // Only copy the first 127 characters if it is         int len = wcslen(catDescription);         if (len>127)            len = 127;         wcsncpy(catinfo.szDescription, catDescription, len);         // Make sure the description is null terminated         catinfo.szDescription[len] = '\0';         hr = pcr->RegisterCategories(1, &catinfo);         pcr->Release();         return hr;      }      // Helper function to register a CLSID as belonging to a component      // category      HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)      {         // Register your component categories information.         ICatRegister* pcr = NULL ;         HRESULT hr = S_OK ;         hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,                               NULL,                               CLSCTX_INPROC_SERVER,                               IID_ICatRegister,                               (void**)&pcr);         if (SUCCEEDED(hr))         {            // Register this category as being "implemented" by            // the class.            CATID rgcatid[1] ;            rgcatid[0] = catid;            hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);         }         if (pcr != NULL)            pcr->Release();         return hr;      }
  2. Modify the DllRegisterServer to mark the control as safe. Locate the implementation of DllRegisterServer in a .cpp file in your project. You will need to add several things to this .cpp file. Include the file that implements CreateComponentCategory and RegisterCLSIDInCategory:
    #include "CatHelp.h"
    Define the GUID associated with the safety component categories:
    const CATID CATID_SafeForScripting     =      {0x7dd95801,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};      const CATID CATID_SafeForInitializing  =      {0x7dd95802,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
    Define the GUID associated with your control. For simplicity, you can borrow the GUID from theIMPLEMENT_OLECREATE_EX macro in the main .cpp file for the control. Adjust the format slightly so that it looks like the following:
    const GUID CDECL BASED_CODE _ctlid =      { 0x43bd9e45, 0x328f, 0x11d0,              { 0xa6, 0xb9, 0x0, 0xaa, 0x0, 0xa7, 0xf, 0xc2 } };
    To mark your control as both Safe for Scripting and Initialization, modify the DllRegisterServer function as follows:
    STDAPI DllRegisterServer(void)      {          AFX_MANAGE_STATE(_afxModuleAddrThis);          if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))              return ResultFromScode(SELFREG_E_TYPELIB);          if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))              return ResultFromScode(SELFREG_E_CLASS);          if (FAILED( CreateComponentCategory(                  CATID_SafeForScripting,                  L"Controls that are safely scriptable") ))                return ResultFromScode(SELFREG_E_CLASS);          if (FAILED( CreateComponentCategory(                  CATID_SafeForInitializing,                  L"Controls safely initializable from persistent data") ))                return ResultFromScode(SELFREG_E_CLASS);          if (FAILED( RegisterCLSIDInCategory(                  _ctlid, CATID_SafeForScripting) ))                return ResultFromScode(SELFREG_E_CLASS);          if (FAILED( RegisterCLSIDInCategory(                  _ctlid, CATID_SafeForInitializing) ))                return ResultFromScode(SELFREG_E_CLASS);          return NOERROR;      }
You would not normally modify the DllUnregisterServer function for these two reasons:
  • You would not want to remove a component category because other controls may be using it.
  • Although there is an UnRegisterCLSIDInCategory function defined, by default DllUnregisterServer removes the control's entry from the registry entirely. Therefore, removing the category from the control's registration is of little use.===============================================

对象 YMvideo 的 ATL 8.0 测试页
  

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

另外的一个参考

转载地址:http://rdgab.baihongyu.com/

你可能感兴趣的文章
深度解密HTTP通信细节
查看>>
日活亿级用户的服务器架构要怎么搭?
查看>>
MySQL 是怎样运行的:从根儿上理解 MySQL
查看>>
开源搜索技术的核心引擎 —— Lucene
查看>>
码洞技术文章大全
查看>>
RPC 服务器之【多进程描述符传递】高阶模型
查看>>
程序员年龄增大后的职业出路是什么?
查看>>
快学 Go 语言 第 1 课 —— Hello World
查看>>
《快学 Go 语言》第 4 课 —— 低调的数组
查看>>
作为程序员,你是如何在工作以后找到女朋友的?
查看>>
一种简单的Failover机制
查看>>
Channel最佳实践之基本规则【译】
查看>>
天下无难试之HTTP协议面试刁难大全
查看>>
深入Python多进程编程基础
查看>>
深入理解RPC——RPC在企业服务中的核心价值
查看>>
跋山涉水 —— 深入 Redis 字典遍历
查看>>
如何解决Java线程池队列过饱问题
查看>>
Lettuce快速入门
查看>>
轻量级框架Spark快速入门
查看>>
蚂蚁金服RPC框架结构分析
查看>>