IE加载ocx时提示控件不安全的解决方法
来源:互联网 发布:张艺兴黄子韬关系知乎 编辑:程序博客网 时间:2024/05/21 06:51
之前编写的ocx控件在ie浏览器加载的时候,会出现一个提示。
这是因为ocx控件有一个ID,而这个ID注册后IE并没有认为它是安全的控件。
我们必须把这个控件注册为安全控件。
新建的mfc Activity项目有三个重要的类,xxApp,xxCtrl,xxPropPage三个类。
1.在xxApp类头文件添加如下函数声明:
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);// Helper function to register a CLSID as belonging to a component// categoryHRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);// Helper function to unregister a CLSID as belonging to a component// categoryHRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
在xxApp类的实现文件添加如下:
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// categoryHRESULT 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;}// HRESULT UnRegisterCLSIDInCategory - Remove entries from the registryHRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid){ ICatRegister *pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); if (SUCCEEDED(hr)) { // Unregister this category as being "implemented" by the class. CATID rgcatid[1] ; rgcatid[0] = catid; hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid); } if (pcr != NULL) pcr->Release(); return hr;}
2.注册GUID
在xxApp.cpp定义两个GUID用来注册控件安全
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}};
const CATID CLSID_SafeItem = {0x3ce7a2fd, 0x1ae9, 0x40b0, 0x83, 0xdb, 0x4a, 0x32, 0xce, 0xb2, 0xcf, 0x30};const GUID CDECL _tlid = { 0x59A67716, 0x53F0, 0x464A, { 0x9D, 0x35, 0x30, 0x24, 0x68, 0xBF, 0x1F, 0xCC } };const WORD _wVerMajor = 1;const WORD _wVerMinor = 0;
注意:CLSID_SafeItem其实就是xxCtrl.cpp里的这个值。
// 初始化类工厂和 guidIMPLEMENT_OLECREATE_EX(CActivePZCtrl, "ACTIVEPZ.ActivePZCtrl.1",0x3ce7a2fd, 0x1ae9, 0x40b0, 0x83, 0xdb, 0x4a, 0x32, 0xce, 0xb2, 0xcf, 0x30)
3.修改注册和反注册的代码
在xxApp.cpp文件的DllRegisterServer函数和DllUnRegisterServer函数。
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);return NOERROR;*///NEW下面是新的注册代码 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( CLSID_SafeItem, CATID_SafeForScripting) )) return ResultFromScode(SELFREG_E_CLASS); if (FAILED( RegisterCLSIDInCategory( CLSID_SafeItem, CATID_SafeForInitializing) )) return ResultFromScode(SELFREG_E_CLASS); return NOERROR;}// DllUnregisterServer - 将项从系统注册表中移除STDAPI DllUnregisterServer(void){/*AFX_MANAGE_STATE(_afxModuleAddrThis);if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))return ResultFromScode(SELFREG_E_TYPELIB);if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))return ResultFromScode(SELFREG_E_CLASS);return NOERROR;*///NEW下面是新的代码 HRESULT hr; AFX_MANAGE_STATE(_afxModuleAddrThis); // Remove entries from the registry. hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing); if (FAILED(hr)) return hr; hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting); if (FAILED(hr)) return hr; if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor)) return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE)) return ResultFromScode(SELFREG_E_CLASS); return NOERROR;}
4.这个提示解决之后,因为IE设置的问题,还会出现如下提示:
可以在internet选项中设置
链接:ActiveX控件开发的一些问题一,如何标记控件为安全
浏览器插件之ActiveX开发(一)
0 0
- IE加载ocx时提示控件不安全的解决方法
- IE加载ocx时提示控件不安全的解决方法
- VB源程序总是提示加载错误,或者不能加载OCX控件解决方法
- Ocx控件在IE滚动时闪烁问题的解决
- 关于OCX控件在ie下调用不了接口的解决方法
- IE浏览器下OCX控件的兼容问题
- IE浏览网页flash.ocx控件加载失败
- 解决IE不能加载OCX控件问题(一)
- 解决IE不能加载OCX控件问题(二)
- IE调试ocx控件
- ocx控件ie调试
- 缺少.ocx等的控件的解决方法
- VB 工程提示不能加载mscomctl.ocx控件错误解决办法
- xp中查找加载的ocx控件
- IE浏览器调用OCX控件的一般方法
- 点击打印出现IE已经阻止此站点用不安全方式使用 ActiveX 控件解决方法
- VC开发的ActiveX加入安全机制,避免IE中提示“在此页上的ActiveX控件,,不安全,你想允许这种交互吗?”
- 网页中"IE限制网页访问脚本或ActiveX控件"的提示问题的解决方法
- 使用iocomp中iplot控件实现接收串口数据并显示曲线
- 2014-2015国内餐饮O2O挑战与趋势
- 在linux上安装JDK,配置环境
- Android.mk文件语法规范及使用模板
- java 集合小结
- IE加载ocx时提示控件不安全的解决方法
- android 防止用户粗暴点击(快速点击)引起的无响应问题。
- iOS uitableview 局部刷新
- 关于C++二维指针
- zoj 1864 自然数幂和
- Codeforces Round #228 (Div. 1) C. Fox and Card Game
- 基于MTK平台的不同安卓版本软件编译的JDK版本GCC版本切换脚本
- iResearch-付费搜索营销操作指南(优化篇)
- NDK 中无法找到头文件 解决方法