Write an ActiveX control that does not eject a warning in the browser

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.