Share via


AfxOleRegisterControlClass

Registers the control class with the Windows registration database.

BOOL AFXAPI AfxOleRegisterControlClass( 
   HINSTANCE hInstance, 
   REFCLSID clsid, 
   LPCTSTR pszProgID, 
   UINT idTypeName, 
   UINT idBitmap, 
   int nRegFlags, 
   DWORD dwMiscStatus, 
   REFGUID tlid, 
   WORD wVerMajor, 
   WORD wVerMinor  
);

Parameters

  • hInstance
    The instance handle of the module associated with the control class.

  • clsid
    The unique class ID of the control.

  • pszProgID
    The unique program ID of the control.

  • idTypeName
    The resource ID of the string that contains a user-readable type name for the control.

  • idBitmap
    The resource ID of the bitmap used to represent the OLE control in a toolbar or palette.

  • nRegFlags
    Contains one or more of the following flags:

    • afxRegInsertable   Allows the control to appear in the Insert Object dialog box for OLE objects.

    • afxRegApartmentThreading   Sets the threading model in the registry to ThreadingModel=Apartment.

    • afxRegFreeThreading   Sets the threading model in the registry to ThreadingModel=Free.

      You can combine the two flags afxRegApartmentThreading and afxRegFreeThreading to set ThreadingModel=Both. See InprocServer32 in the Windows SDK for more information on threading model registration.

    Note

    In MFC versions before MFC 4.2, the int nRegFlags parameter was a BOOL parameter, bInsertable, that allowed or disallowed the control to be inserted from the Insert Object dialog box.

  • dwMiscStatus
    Contains one or more of the following status flags (for a description of the flags, see OLEMISC enumeration in the Windows SDK):

    • OLEMISC_RECOMPOSEONRESIZE

    • OLEMISC_ONLYICONIC

    • OLEMISC_INSERTNOTREPLACE

    • OLEMISC_STATIC

    • OLEMISC_CANTLINKINSIDE

    • OLEMISC_CANLINKBYOLE1

    • OLEMISC_ISLINKOBJECT

    • OLEMISC_INSIDEOUT

    • OLEMISC_ACTIVATEWHENVISIBLE

    • OLEMISC_RENDERINGISDEVICEINDEPENDENT

    • OLEMISC_INVISIBLEATRUNTIME

    • OLEMISC_ALWAYSRUN

    • OLEMISC_ACTSLIKEBUTTON

    • OLEMISC_ACTSLIKELABEL

    • OLEMISC_NOUIACTIVATE

    • OLEMISC_ALIGNABLE

    • OLEMISC_IMEMODE

    • OLEMISC_SIMPLEFRAME

    • OLEMISC_SETCLIENTSITEFIRST

  • tlid
    The unique ID of the control class.

  • wVerMajor
    The major version number of the control class.

  • wVerMinor
    The minor version number of the control class.

Return Value

Nonzero if the control class was registered; otherwise 0.

Remarks

This allows the control to be used by containers that are OLE-control aware. AfxOleRegisterControlClass updates the registry with the control's name and location on the system and also sets the threading model that the control supports in the registry. For more information, see Technical Note 64, "Apartment-Model Threading in OLE Controls," and About Processes and Threads in the Windows SDK.

Example

// Member function implementation of class COleObjectFactory::UpdateRegistry  
//
BOOL CMyAxCtrl::CMyAxCtrlFactory::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 
    // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable. 

    if (bRegister)
        return AfxOleRegisterControlClass(
            AfxGetInstanceHandle(),
            m_clsid,
            m_lpszProgID,
            IDS_NVC_MFCAXCTL,
            IDB_NVC_MFCAXCTL,
            afxRegInsertable | afxRegApartmentThreading,
            _dwMyOleMisc,
            _tlid,
            _wVerMajor,
            _wVerMinor);
    else 
        return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}

The above example demonstrates how AfxOleRegisterControlClass is called with the flag for insertable and the flag for apartment model ORed together to create the sixth parameter:

          afxRegInsertable | afxRegApartmentThreading,

The control will show up in the Insert Object dialog box for enabled containers, and it will be apartment model-aware. Apartment model-aware controls must ensure that static class data is protected by locks, so that while a control in one apartment is accessing the static data, it isn't disabled by the scheduler before it is finished, and another instance of the same class starts using the same static data. Any accesses to the static data will be surrounded by critical section code.

Requirements

Header: <afxctl.h>

See Also

Reference

AfxOleRegisterPropertyPageClass

AfxOleRegisterTypeLib

AfxOleUnregisterClass

AfxOleUnregisterTypeLib

Concepts

MFC Macros and Globals