AfxOleRegisterControlClass

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

#include <afxctl.h>

Return Value

Nonzero if the control class was registered; otherwise 0.

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:

Note   In MFC versions prior to 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 OLE Programmer's Reference):

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.

Remarks

Registers the control class with the Windows registration database. 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 Win32 SDK.

Example

// Member function implementation of class COleObjectFactory::UpdateRegistry 
//
BOOL CMyApartmentAwareCtrl::CApartmentCtrlFactory::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_APARTMENT,
         IDB_APARTMENT,
         afxRegInsertable | afxRegApartmentThreading,
         _dwApartmentOleMisc,
         _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.

See Also   AfxOleRegisterPropertyPageClass, AfxOleRegisterTypeLib, AfxOleUnregisterClass, AfxOleUnregisterTypeLib