三、MFC Activex 安全问题:
1、在默认环境下,编译的MFC Activex控件,只能在本地代码中运行,即在http://localhost/xxx/xxx.htm中执行,而在http://127.0.0.1/xxx/xxx.htm中提示无相关属性,需要设置其初始化和脚本运行的安全性
ActiveX在远程IE页面上执行,需要实现安全接口。
在ATL写的ActiveX中,用IObjectSafety。
http://support.microsoft.com/kb/168371/en-us
在MFC写的ActiveX中,直接修改注册表。
http://support.microsoft.com/kb/161873/en-us
mfc实现的ocx,要在app实现文件中包括两个文件:
在ActivexDemo.cpp 文件中实现以下方法
#include " stdafx.h "
#include " ActivexDemo.h "
#include < comcat.h >
#include < objsafe.h >
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CActivexDemoApp theApp;
const GUID CDECL BASED_CODE _tlid =
{ 0x344B8576 , 0xAB2C , 0x4D38 , { 0xAE , 0x7 , 0x73 , 0x74 , 0x22 , 0x89 , 0x72 , 0xEA } };
const WORD _wVerMajor = 1 ;
const WORD _wVerMinor = 0 ;
// CActivexDemoApp::InitInstance - DLL 初始化
BOOL CActivexDemoApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
// TODO: 在此添加您自己的模块初始化代码。
}
return bInit;
}
// CActivexDemoApp::ExitInstance - DLL 终止
int CActivexDemoApp::ExitInstance()
{
// TODO: 在此添加您自己的模块终止代码。
return COleControlModule::ExitInstance();
}
// 创建组件种类
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 HKCRComponent 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] = '