描述:
各位高手:
我写了一个OCX控件,把它装入网页中,并且我也通过如下代码进行了注册,但为什么还是被WEB页面阻止呢,依然弹出警告说不安全。
////////////////////////////////////////////////////////////////
// Copied from the ActiveX SDK
// This code is used to register and unregister a
// control as safe for initialization and safe for scripting
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 (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;
}
/*****************************************
在 xxxctl.cpp 文件中添加如下两个头文件
*****************************************/
#include "comcat.h"
#include "objsafe.h"
/*****************************************
修改如下函数
*****************************************/
BOOL CxxxCtrl::CxxxCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegInsertable | afxRegApartmentThreading to afxRegInsertable.
if (bRegister)
{
HRESULT hr = S_OK ;
// register as safe for scripting
hr
您可能想查找下面的文章:
- 怎样利用ActiveX来的使得服务器端获得客户端的地址,服务器端和客户端都是嵌在网页中的
- 请问vs里怎么把智能设备ocx注册到vs里,使得在ActiveX选择框里能看到???
- 怎样用VC做ACTIVEX可以使得一个控件能导出多个包装类?
- 在双CPU的系统中,如何保证或者是如何使得某一个线程始终占有CPU的控制使用权呢???
- 如何实现一个程序,使得该程序能自动在其他dialog中的CEdit对象填入数据以及点击按钮
- 如何定义一个DLL的方法,使得这个方法
- 如何用mfc制作一個靜態鏈接庫,使得我的應用程序只調用lib和h來使用其中的函數就可以?
- 如何改变exe中的变量i,使得i在两个进程开始执行时的值不一样?
- 如何使listctrl中出现的表一样格式的数据能平均分它的宽度,使得数据一开始出现像表一样的,而不是使很多列的数据看不到,在线等
- 如何在通过dll打开一个对话框a,a又打开另一对话框b,b又打开一个c对话框,如何定义使得c中可以用a中定义的变量。