2010. 1. 6. 06:26

다중 OLE 객체 인스턴스 지원하기

OLE 자동화 객체를 생성할 때 매번 새로운 인스턴스를 띄우게 하기 위해서는 아래처럼 IMPLEMENT_OLECREATE 를 재정하여야 한다. 원래는 FALSE 로 되어 있어서 단일 인스턴스만 지원하게 되어 있기 때문에 이 값만 TRUE 로 변경한 것이다.

 #define MY_IMPLEMENT_OLECREATE(class_name, external_name, l, w1, w2,
        b1, b2, b3, b4, b5, b6, b7, b8) \
        COleObjectFactory class_name::factory(class_name::guid, \
        RUNTIME_CLASS(class_name), TRUE, _T(external_name)); \
        const GUID CDECL class_name::guid = \
        { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \


MY_IMPLEMENT_OLECREATE(CMyClass, "Test", 0xc9c99ae0, 0xad41, 0x101b,
                       0x83, 0xea, 0x0, 0x0, 0x83, 0x78, 0xac, 0x8b)

그리고 항상 새로운 인스턴스를 생성하기 위해서는 :

( 그냥 이 매크로만 재정의해서 사용하는 경우에는 COM 객체가 연결되지 않은 기존의 인스턴스가 실행되어 있는 경우 이 인스턴스로부터 COM 객체를 생성한다. )

InitInstance 에서 COleTemplateServer::RegisterAll(); 함수를 적절한 곳에 이동시킨다.

     // App was launched with /Embedding or /Automation switch.
    // Run app as automation server.
    if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
    {
        COleTemplateServer::RegisterAll();
        // Don't show the main window
        return TRUE;
    }

참고 : http://support.microsoft.com/kb/141154/en-us/