[개발/VC] ActiveX 보안코드 삽입
디지털 서명해도 아래 보안 코드를 삽입하지 않으면 다른 컴퓨터에서
엑티브엑스 다운받을때 받지 못하는 수가 있습니다.
그니까 그냥 해주면 좋을듯...
BOOL CActiveCoolCtrl::CActiveCoolCtrlFactory::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)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_ACTIVECOOL,
IDB_ACTIVECOOL,
afxRegApartmentThreading,
_dwActiveCoolOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
다음 코드로 바꾸시면 됩니다.
===>
//////////////////////////////////////////////////////////////////////
// ocx 보안 코드 <bro>
#include "comcat.h"
#include "objsafe.h"
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{
ICatRegister* pcr = NULL ; // interface pointer
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) )
{
CATID rgcatid[1];
rgcatid[0] = catid;
hr = pcr->UnRegisterClassImplCategories( clsid, 1, rgcatid );
}
if( pcr != NULL )
pcr->Release();
return hr;
}
BOOL CActiveCoolCtrl::CActiveCoolCtrlFactory::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)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_ACTIVECOOL,
IDB_ACTIVECOOL,
afxRegApartmentThreading,
_dwActiveCoolOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
*/
if(bRegister)
{
BOOL retval = AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_ACTIVECOOL,
IDB_ACTIVECOOL,
afxRegApartmentThreading,
_dwActiveCoolOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
// mark as safe for scripting--failure OK
HRESULT hr = CreateComponentCategory(CATID_SafeForScripting,
L"Controls that are safely scriptable");
if (SUCCEEDED(hr))
// only register if category exists
RegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting);
// don't care if this call fails
// mark as safe for data initialization
hr = CreateComponentCategory(CATID_SafeForInitializing,
L"Controls safely initializable from persistent data");
if (SUCCEEDED(hr))
// only register if category exists
RegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing);
// don't care if this call fails
return retval;
}
else
{
UnregisterCLSIDInCategory( m_clsid, CATID_SafeForInitializing );
UnregisterCLSIDInCategory( m_clsid, CATID_SafeForScripting );
return AfxOleUnregisterClass( m_clsid, m_lpszProgID );
}
}
// ocx 보안 코드 </bro>
//////////////////////////////////////////////////////////////////////
반응형
'IT-개발,DB' 카테고리의 다른 글
[개발/VC] ActiveX에서 키, 탭키등을 먹게 하기 (0) | 2011.09.27 |
---|---|
[개발/VC] ActiveX 컨트롤에서 자신을 로딩한 웹브라우저 포인터 구하기 (0) | 2011.09.27 |
[개발/VC] 클릭했을때 이벤트 얻기 (0) | 2011.09.27 |
[개발/VC] 웹페이지 마우스 위치에 있는 엘리먼트 얻어오기 (0) | 2011.09.27 |
[개발/MFC] 웹 페이지 <form 태그의 a 태그 anchor 값 찾기 (0) | 2011.09.27 |
댓글