¾ÈÁ¤¼ºÀ» º¸ÀåÇÏ´Â ActiveX ÄÁÆ®·Ñ Á¦ÀÛ

 

  ÀϹÝÀûÀÎ ¹æ½ÄÀ¸·Î(ActiveX ÄÁÆ®·Ñ Á¦ÀÛ¿¡¼­ ¼³¸íÇÑ ¹æ½Ä) ActiveX ÄÁÆ®·ÑÀ» ÀÛ¼ºÇϸé, À¥¿¡¼­ ActiveX »ç¿ëÀÇ ¸¶Áö¸· ºÎºÐ¿¡ ActiveX ÄÁÆ®·Ñ°ú Html °´Ã¼¿ÍÀÇ ¿¬µ¿ ½Ã¿¡ º¸¾È ¹®Á¦°¡ ÀÖ´Ù´Â °ÍÀ» ¼³¸íÇß´Ù. ÀÌÁ¦ ±× ÇØ°á¹ýÀ» ¼³¸íÇϰíÀÚ ÇÑ´Ù.

°£´ÜÈ÷ ¼³¸íÇϸé ActiveX ÄÁÆ®·Ñ ·çƾ¿¡ ¾ÈÁ¤¼ºÀ» º¸ÀåÇÏ´Â ·çƾ(¾ÈÁ¤¼ºÀ» º¸ÀåÇÏ´Â clsid¸¦ ·¹Áö½ºÆ®¸®¿¡ µî·ÏÇÏ´Â ·çƾ)À» Ãß°¡ÇØ¾ß ÇÑ´Ù. ¸ÕÀú ·¹Áö½ºÆ®¸®¿¡ clsid¸¦ µî·ÏÇÏ´Â ÇÔ¼ö¸¦ ÀÛ¼ºÇÏ°í ½ÇÁ¦ ActiveX ÄÁÆ®·Ñ Á¦ÀÛ¿¡¼­ ÀÛ¼ºÇÑ ÄÁÆ®·Ñ¿¡ Ãß°¡¸¦ ÇØº¸±â·Î ÇÑ´Ù.

 

ÇÔ¼ö ÀÛ¼º

´ÙÀ½°ú °°Àº ³»¿ëÀÇ 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;
}

 

À§ ³»¿ë ¶ÇÇÑ ±×´ë·Î »ç¿ëÇÏ¸é µÇ¹Ç·Î ÀÌÇØÇϱâ À§Çؼ­ ³Ê¹« ¸¹Àº ³ë·ÂÀ» µéÀÌÁö´Â ¸»±â ¹Ù¶õ´Ù.

ÄÄÆÄÀÏÀ» ÇÏ°í ½ÇÇàÀ» ÇÏ¸é º¸¾È ´ëÈ­ »óÀÚ°¡ »ý¼ºµÇÁö ¾Ê°í Àß µ¿À۵ȴٴ °ÍÀ» ¾Ë ¼ö ÀÖ´Ù.

 

´Ù¿î·Îµå