ActiveX控件注册表安全描述及cab包发布注意事项
来源:互联网 发布:soul软件 编辑:程序博客网 时间:2024/05/19 04:02
最近做了一个ActiveX控件,要将控件描述和初始化为安全的,否则浏览器在加载控件时会出现警告信息。对于MFC ActiveX控件需要进行一下设置:
1.在工程中添加一下两个文件cathelp.h 和 cathelp.cpp来实现CreateComponentCategory , RegisterCLSIDInCategory两个帮助函数。
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; }
- 在此文件中包含定义CreateComponentCategory,RegisterCLSIDInCategory的头文件
#include "CatHelp.h"
- 定义与安全组件相关的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}};
- 将DllRegisterServer函数改为如下代码
STDAPI DllRegisterServer(void) { AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) //_tlid的定义一般已经自动生成,形式为:const GUID CDECL BASED_CODE _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) )) //_ctlid 是此空间类型的id,定义形式为GUID clsid = {0x810d0c77, 0x33a, 0x4c39, {0x55, 0xee, 0x68, 0xcf, 0xe2, 0x20, 0x3, 0xc2}}; return ResultFromScode(SELFREG_E_CLASS); if (FAILED( RegisterCLSIDInCategory( _ctlid, CATID_SafeForInitializing) )) return ResultFromScode(SELFREG_E_CLASS); return NOERROR; }
在打包cab文件发布时遇到了另外一个问题:
将inf文件及ocx插件打成cab包并签名后正常发布,也可以通过浏览器加载此控件,并且此时查看注册表的设置与直接在vs工程中安装后是一样的。但在调用ocx中的接口时一直显示“不支持此对象属性”之类的错误,最后经过多次测试将与工程中生成的与ocx文件同名的.lic文件一起打包cab后就可以正常加载了。
希望以上内容对大家有帮助。
- ActiveX控件注册表安全描述及cab包发布注意事项
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- asp.net 开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包(转)
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包
- C#开发ActiveX控件及制作CAB包(转)
- C#开发ActiveX控件及制作CAB包
- 制作Cab包,签名发布ActiveX
- 发布ActiveX控件(把ocx做成cab发布) --activex数字签名
- 九家页游公司创始人提供数据质疑香椽
- visualbox 镜像文件操作
- linux awk 数组操作详细介绍
- ubuntu安装软件列表与系统配置
- iPhone 5创新乏力 苹果走下神坛
- ActiveX控件注册表安全描述及cab包发布注意事项
- POJ 2296 Map Labeler(2-sat)
- IE8开发人员工具(调试工具)无法使用
- Android推送通知指南
- 百度文库免积分免费下载工具的原理与实现
- extern "C"的用法解析
- 类的内存布局-sizeof(类对象)
- sql server2008中无法使用数据库关系图
- Mysql常用命令大全