据说可以将Activex控件在IE中不显示安全提示

 据说可以将Activex控件在IE中不显示安全提示,先收藏,有空再验证。

转csdn网友shepherds()

我用的是这种方法:
   在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无任何警告,你可试一下,我用的没问题

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值