Compile ActiveX control that does not bring up warnings in the browser
When we compile ActiveX controls, if we use them in a browser, a prompt indicating that the running scripts are not secure is often displayed. If we use them, this will cause great inconvenience.
According to the description of msdn, there are usually two methods: Implementing the iobjectsafe interface and modifying the registry. Generally, if you use ATL to develop ActiveX controls, you can use the iobjectsafe interface method. If you use MFC for development, I think it is more convenient to modify the registry. The second method is as follows:
Two files must be included.
# Include "comcat. H"
# Include "objsafe. H"
// CLSID of the control, which is used in the Registry
Const guid cdecl clsid_safeitem = {0x7ae7497b, 0xcad8, 0x4e66,
{0xa5, 0x8b, 0xdd, 0xe9, 0xbc, 0xaf, 0x6b, 0x61 }};
// Version Control
Const word _ wvermajor = 1;
// Times version number
Const word _ wverminor = 0;
//////////////////////////////////////// /////////////////////////////
// Ciccardapp: initinstance-DLL Initialization
Bool ciccardapp: initinstance ()
{
Bool binit = colecontrolmodule: initinstance ();
If (binit)
{
}
Return binit;
}
//////////////////////////////////////// //////////////////////////////
// Ciccardapp: exitinstance-DLL termination
Int ciccardapp: exitinstance ()
{
Return colecontrolmodule: exitinstance ();
}
//////////////////////////////////////// //////////////////////////////
// Create Component Types
Hresult createcomponentcategory (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;
}
// Register the component type
Hresult registerclsidincategory (refclsid CLSID, 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;
}
// Uninstall Component Types
Hresult unregisterclsidincategory (refclsid CLSID, 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;
}
// Dllregisterserver-adds entries to the system registry
Stdapi dllregisterserver (void)
{
Hresult hr;
Afx_manage_state (_ afxmoduleaddrthis );
If (! Afxoleregistertypelib (AfxGetInstanceHandle (), _ tlid ))
Return resultfromscode (selfreg_e_typelib );
If (! Coleobjectfactoryex: updateregistryall (true ))
Return resultfromscode (selfreg_e_class );
// Tag control initialization security.
// Create an initialized security component type
HR = createcomponentcategory (catid_safeforinitializing,
L "controls safely initializable from persistent data! ");
If (failed (HR ))
Return hr;
// Register for initialization Security
HR = registerclsidincategory (clsid_safeitem, catid_safeforinitializing );
If (failed (HR ))
Return hr;
// Flag control Script Security
// Create a script security component type
HR = createcomponentcategory (catid_safeforscripting, l "controls safely Scriptable! ");
If (failed (HR ))
Return hr;
// Register the script security component type
HR = registerclsidincategory (clsid_safeitem, catid_safeforscripting );
If (failed (HR ))
Return hr;
Return noerror;
}
//////////////////////////////////////// //////////////////////////
// Dllunregisterserver-removes entries from the system registry
Stdapi dllunregisterserver (void)
{
Hresult hr;
Afx_manage_state (_ afxmoduleaddrthis );
If (! Afxoleunregistertypelib (_ tlid, _ wvermajor, _ wverminor ))
Return resultfromscode (selfreg_e_typelib );
If (! Coleobjectfactoryex: updateregistryall (false ))
Return resultfromscode (selfreg_e_class );
// Delete the control initialization security entry.
HR = unregisterclsidincategory (clsid_safeitem, catid_safeforinitializing );
If (failed (HR ))
Return hr;
// Security entry for deleting Control Scripts
HR = unregisterclsidincategory (clsid_safeitem, catid_safeforscripting );
If (failed (HR ))
Return hr;
//////////////////////////
Return noerror;
}
Transfer from csdn Forum