分享

js 调用activex的安全代码

 水中麒麟 2014-04-25

/////////////ZOGNA//////DOWN////////安全//否则JSP无法调用////////
#include "comcat.h"
#include <objsafe.h>
/////////////ZOGNA////////UP//////安全//否则JSP无法调用////////
官工 10:50:52

/////////////ZOGNA//////DOWN////////安全//否则JSP无法调用////////
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;
}
BOOL CUVSSocxCtrl::CUVSSocxCtrlFactory::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
// afxRegApartmentThreading to 0.

if (bRegister)
{
HRESULT hr = S_OK ;

// register as safe for scripting

hr = CreateComponentCategory(CATID_SafeForScripting,
L"Controls that are safely scriptable");

if (FAILED(hr))
return FALSE;

hr = RegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting);

if (FAILED(hr))
return FALSE;

// register as safe for initializing

hr = CreateComponentCategory(CATID_SafeForInitializing,
L"Controls safely initializable from persistent data");

if (FAILED(hr))
return FALSE;

hr = RegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing);

if (FAILED(hr))
return FALSE;

return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_UVSSOCX,
IDB_UVSSOCX,
afxRegInsertable | afxRegApartmentThreading,
_dwUVSSocxOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
}
else
{
HRESULT hr = S_OK ;

hr = UnRegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting);

if (FAILED(hr))
return FALSE;

hr = UnRegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing);

if (FAILED(hr))
return FALSE;

return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
}

/////////////ZOGNA////////UP//////安全//否则JSP无法调用////////

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多