IE加载ocx时提示控件不安全的解决方法
2015-01-26 09:35
1046 查看
之前编写的ocx控件在ie浏览器加载的时候,会出现一个提示。
这是因为ocx控件有一个ID,而这个ID注册后IE并没有认为它是安全的控件。
我们必须把这个控件注册为安全控件。
新建的mfc Activity项目有三个重要的类,xxApp,xxCtrl,xxPropPage三个类。
1.在xxApp类头文件添加如下函数声明:
在xxApp类的实现文件添加如下:
2.注册GUID
在xxApp.cpp定义两个GUID用来注册控件安全
同时在xxApp.cpp文件定义安全的CLSID
注意:CLSID_SafeItem其实就是xxCtrl.cpp里的这个值。
3.修改注册和反注册的代码
在xxApp.cpp文件的DllRegisterServer函数和DllUnRegisterServer函数。
4.这个提示解决之后,因为IE设置的问题,还会出现如下提示:
可以在internet选项中设置
链接:ActiveX控件开发的一些问题一,如何标记控件为安全
浏览器插件之ActiveX开发(一)
这是因为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 // category HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid); // Helper function to unregister a CLSID as belonging to a component // category HRESULT 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 // 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; } // HRESULT UnRegisterCLSIDInCategory - Remove entries from the registry HRESULT 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}};
同时在xxApp.cpp文件定义安全的CLSID
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里的这个值。
// 初始化类工厂和 guid IMPLEMENT_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开发(一)
相关文章推荐
- IE加载ocx时提示控件不安全的解决方法
- VB源程序总是提示加载错误,或者不能加载OCX控件解决方法
- 关于4A网络安全管控平台控件加载失败的解决方法
- 关于OCX控件在ie下调用不了接口的解决方法
- 解决IE不能加载OCX控件问题(二)
- 点击打印出现IE已经阻止此站点用不安全方式使用 ActiveX 控件解决方法
- 解决IE不能加载OCX控件问题(一)
- 解决“ .dll(或.ocx)控件已加载,但对DllregisterServer的调用失败,错误代码为0x80004005”问题的两种终极方法:SubInACL安装 VS 命令提示符
- 安装IE7之后导致VB6IE控件无法加载WebBrowser的解决方法
- 打开VB开发工具提示:Imagelist来自mscomctl.ocx控件出错,可能是mscomctl.ocx过期,解决方法
- WPF编辑器无法加载用户控件,提示找不到类型错误的解决方法
- Vista系统中IE提示证书错误解决方法[图文]
- word打不开,总提示进入安全模式 的解决方法
- ExtJs TreePanel使用TreeLoader在IE下无法正常加载显示的解决方法
- [转]ajax项目提示我缺少Microsoft.Web.Preview.dl和未能加载AjaxControlToolkit程序集解决方法
- QTP弹出提示"当前安全设置禁止安全运行该页中的activeX控件"的解决方法
- IE或软件加载页中提示脚本错误的解决办法集合
- 用IE打开Reporting Service时提示权限不足的解决方法
- QTP提示"当前安全设置禁止安全运行该页中的activeX控件"的解决方法
- scriptx.cab无法加载控件解决方法