When we write ActiveX controls, if used in the browser, often will pop up now run the script unsafe prompts, if the use of customers, will bring great inconvenience. As described in MSDN, there are usually two kinds of implementations for IOBJECTSAFE interfaces, one by modifying the registry. In general, if you develop ActiveX controls with ATL, you use a method that implements the Objectsafe interface. If using MFC development, I think it is more convenient to modify the registry method. Here's the second method:
To include two files
#include "comcat.h"
#include "Objsafe.h"
The CLSID of this control, with the registry
const GUID CDECL CLSID_SafeItem =
{ 0x7AE7497B, 0xCAD8, 0x4E66, { 0xA5,0x8B,0xDD,0xE9,0xBC,0xAF,0x6B,0x61 } };
Create component types
HRESULT createcomponentcategory (CATID CATID, wchar* catdescription)
{
icatregister* PCR = NULL;
HRESULT hr = S_OK;
hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr,
NULL, Clsctx_inproc_server, Iid_icatregister, (VO id**) &PCR);
if (FAILED (HR)
return to HR;
Make sure the Hkcr\component categories\{. CatID ...} The
//key is registered.
CategoryInfo Catinfo;
Catinfo.catid = catid;
Catinfo.lcid = 0x0409;//中文版
//Make sure the provided description is not too long.
Only copy the "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] = ' ';
hr = pcr->registercategories (1, &catinfo);
pcr->release ();
return HR;
}
Registering component types
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;
}