zoukankan      html  css  js  c++  java
  • ActiveX去除IE警告框方法

    在classview下,向目录的第一个.h文件(即App启动头文件)中加入以下内容:

    //创建Component Categories中的初始化安全和脚本安全项
    HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);
    //在CLSID中创建与Component Categories中初始化安全和脚本安全项中相对应的implemented Categories项
    HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
    //注销与CLSID中的相应implemented Categories项,一般用不到,因为其它程序可能也会用到这此项
    HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid);

    extern const GUID CDECL _tlid;
    extern const GUID CDECL CLSID_SafeItem;

    extern const WORD _wVerMajor;
    extern const WORD _wVerMinor;

    在对就的.cpp文件中加入以下内容,如果原来程序中已经有的,只改动其中的多余部分即可:

    //设置控件与注册表相关的类型库ID,后面跟有version(1.0)字样,从本工程的.idl文件中获取
    const GUID CDECL BASED_CODE _tlid =
    { 0xB926A326, 0xBE91, 0x4337, { 0xA1, 0xDC, 0x76, 0x1B, 0x73, 0x15, 0x6B, 0x23 } };
    //控件在注册表中的CLSID,后面跟有control字样,从本工程的.idl文件中获取
    const GUID CDECL CLSID_SafeItem =
    { 0xAF546E3F, 0xB5B8, 0x42D6, {0xBB, 0x74, 0x84, 0xB7, 0x25, 0xC0, 0x38, 0x4D}};

    const WORD _wVerMajor = 1;
    const WORD _wVerMinor = 0;

    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);
    //创建脚本安全“补充”项,非CLSID中
    hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");
    if (FAILED(hr))
    return hr;
    //创建初始化安全“补充”项,非CLSID中
    hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!");
    if (FAILED(hr))
    return hr;
    //设置控件CLSID中补充项的脚本安全项,与“补充”项中的脚本安全项对应
    hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
    if (FAILED(hr))
    return hr;
    //设置控件CLSID中补充项的初始化安全项,与“补充”项中的初始化安全项对应
    hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
    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);

    // 删除控件初始化安全入口.
    //hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
    //if (FAILED(hr))
    //return hr;
    // 删除控件脚本安全入口
    //hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
    //if (FAILED(hr))
    //return hr;

    return NOERROR;
    }

    // 创建组件种类
    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;
    }

    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 (FAILED(hr))
    return hr;
    }
    if (pcr != NULL)
    pcr->Release();
    return hr;
    }


    HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID 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;
    }

    加入以上代码后IE无任何警告。我的环境是XP SP2 + VC6.0

  • 相关阅读:
    C语言II作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I博客作业12—学期总结
    第一次作业
    C语言I博客作业02
    C语言I博客作业11
    C语言||作业01
  • 原文地址:https://www.cnblogs.com/tyjsjl/p/2156110.html
Copyright © 2011-2022 走看看