Supporting Static Type Information

To support static type information, your ActiveX designer has to implement the IProvideClassInfo interface. The interface has a single method, GetClassInfo. If the designer doesn't support dynamic type information, the host gets type information from GetClassInfo after creating and loading the object and before activating it.

The GetClassInfo method returns a pointer to a type information object that describes the incoming and outgoing interfaces to the ActiveX designer. In the following example, the method gets a pointer to the designer's type library, and through it, uses the ITypeLib interface to retrieve the type information.

<STYLE>STDMETHODIMP MyDesigner::GetClassInfo (LPTYPEINFO FAR* ppTI)
{
    *ppTI = NULL;                     // Default value if failure.
    ITypeInfo *pITypeInfo = NULL;
    ITypeLib  *pITypeLib  = NULL;

    // Get type library.
    hresult = LoadTypeLib (g_pTypeLibName, &pITypeLib);
    if (SUCCEEDED(hresult) != TRUE)
        { ASSERT(FALSE); return E_NOINTERFACE;}

    //    Note: If loaded it, will have a global reference to it.
    //    Free this later.

    // Get the type information of the coclass from the library.
    hresult = pITypeLib -> GetTypeInfoOfGuid 
            (m_pDesigner->m_clsidPersist, &pITypeInfo);
    
    // Assign the typeInfo return value.
    // The caller should free this.
    *ppTI = pITypeInfo;

    // Release reference.
    pITypeLib->Release(); 
}

The example retains the globally unique identifier (GUID) of the designer's coclass in the global structure pointed to by m_pDesigner, so it uses the GetTypeInfoOfGuid method to obtain the type information. (Alternatively, if you have the index into the type information, you can use the GetTypeInfo method instead.) Then it simply returns the type information object to the caller.