我们在编写ActiveX控件时,如果用在浏览器中,经常都会弹出现在运行的脚本不安全的提示, 如果给客户使用,将会带来极大不便。按照MSDN的介绍通常有两种一种是实现IObjectSafe接口,一种是通过修改注册表的方法。一般如果用ATL开发ActiveX控件,就用实现ObjectSafe接口的方法。如果用MFC开发,我觉得还是用修改注册表的方法比较方便。下面我们将第二种方法:
要包括两个文件
1.#include "comcat.h"2.#include "Objsafe.h"// 本控件的CLSID,注册表用
1.const GUID CDECL CLSID_SafeItem =2.{ 0x7AE7497B, 0xCAD8, 0x4E66, { 0xA5,0x8B,0xDD,0xE9,0xBC,0xAF,0x6B,0x61 } };// 创建组件种类
01.HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)02.{03.ICatRegister* pcr = NULL ;04.HRESULT hr = S_OK ;05. 06.hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,07.NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);08.if (FAILED(hr))09.return hr;10. 11.// Make sure the HKCRComponent Categories{..catid...}12.// key is registered.13.CATEGORYINFO catinfo;14.catinfo.catid = catid;15.catinfo.lcid = 0x0409 ; // english16. 17.// Make sure the provided description is not too long.18.// Only copy the first 127 characters if it is.19.int len = wcslen(catDescription);20.if (len>127)21.len = 127;22.wcsncpy(catinfo.szDescription, catDescription, len);23.// Make sure the description is null terminated.24.catinfo.szDescription[len] = ''