织梦CMS - 轻松建站从此开始!

罗索实验室

当前位置: 主页>杂项技术>PC常识>

ActiveX控件去除IE警告框的方法!!

罗索客 发布于 2007-03-08 16:54 点击:次 
在classview下,向目录的第一个.h文件(即App启动头文件)中加入以下内容: //创建Component Categories中的初始化安全和脚本安全项 HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription); //在CLSID中创建与Component Categories中初始化安全和脚本
TAG:

在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无任何警告

(iwgh)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200703/6579.html]
本文出处: 作者:iwgh
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容