상세 컨텐츠

본문 제목

Active X 인증 관련 (안전한 인증)

프로그래밍 관련/프로그래밍 관련팁

by AlrepondTech 2009. 6. 25. 14:19

본문

반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

http://jys92.com.ne.kr/VisualC/SafityActiveXControl.htm

 인용

함수 작성다음과 같은 내용의 cathelp.h라는 파일을 작성한다.
//--------------------------------------------------------------------------------
//cathelp.h
#if !defined(__CATHELP_H)
#define __CATHELP_H
#include "comcat.h"// Helper function to create a component category and associated
// description
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);
// Helper function to register a CLSID as belonging to a component
// category
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
#endif

//--------------------------------------------------------------------------------
//cathelp.cpp

#include "stdafx.h"
#include "comcat.h"
// Helper function to create a component category and associated
// description
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;
}
// Helper function to register a CLSID as belonging to a component
// category
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;
}

  위의 루틴의 내용을 이해하기 위해서 노력할 필요는 없다. 단지 "레지스트리에 clsid를 등록하는 함수구나"라고만 이해하고 넘어가기 바란다.

 

Test Control에 추가App 파일(여기서는 Test.cpp)를 열어 다음과 같이 위에서 작성한 cathelp.h를 include한다.#include "cathelp.h"조금 아래에 다음과 같이 _tlid가 선언되어 있는 것을 볼 수 있을 것이다(_tlid에 할당된 값은 프로그램 마다 다르다). const GUID CDECL BASED_CODE _tlid =
                { 0x9b548709, 0xc3df, 0x4956, { 0x9f, 0x65, 0x29, 0x28, 0xca, 0xbb, 0x6e, 0xc8 } };
바로 아래에 비슷한 3개를 더 등록해야 한다.두 개는 다음과 같이 안정성을 보장하기 위해 예약된(고정된) clsid이고,const CATID CATID_SafeForScripting     =
                {0x7dd95801,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
const CATID CATID_SafeForInitializing  =
                {0x7dd95802,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
나머지 하나는 ctrl 파일(여기서는 testctrl.cpp)에 있는 다음과 같은 내용을 복사해 와서,IMPLEMENT_OLECREATE_EX(CTestCtrl, "TEST.TestCtrl.1",
        0xd886696, 0xc7ce, 0x11d3, 0xa1, 0x75, 0x8, 0, 0x2b, 0xf1, 0x75, 0x7)
다음과 같이 변경(_ctlid 선언)하면 된다.const GUID CDECL BASED_CODE _ctlid =
        {0xd886696, 0xc7ce, 0x11d3, 0xa1, 0x75, 0x8, 0, 0x2b, 0xf1, 0x75, 0x7}

 

이제 App 파일에 있는 다음과 같은 함수에 레지스트리 등록 루틴을 추가하면된다.


//----------------------------------------------------------------

STDAPI DllRegisterServer(void)
{
        AFX_MANAGE_STATE(_afxModuleAddrThis);
        if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
                return ResultFromScode(SELFREG_E_TYPELIB);
        if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
                return ResultFromScode(SELFREG_E_CLASS);
        return NOERROR;
}
//-------------------------------------------------------------

// 추가함수
STDAPI DllRegisterServer(void)
{
        AFX_MANAGE_STATE(_afxModuleAddrThis);
        if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
                return ResultFromScode(SELFREG_E_TYPELIB);
        if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
                return ResultFromScode(SELFREG_E_CLASS);
        if (FAILED( CreateComponentCategory(CATID_SafeForScripting, L"Controls that are safely scriptable") ))
                return ResultFromScode(SELFREG_E_CLASS);
        if (FAILED( CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data") ))
                return ResultFromScode(SELFREG_E_CLASS);
        if (FAILED( RegisterCLSIDInCategory(_ctlid, CATID_SafeForScripting) ))
                return ResultFromScode(SELFREG_E_CLASS);
        if (FAILED( RegisterCLSIDInCategory(_ctlid, CATID_SafeForInitializing) ))
                return ResultFromScode(SELFREG_E_CLASS);
        return NOERROR;
}

 

 

=================================

=================================

=================================

 

반응형


관련글 더보기

댓글 영역