IMoniker—Class Moniker Implementation

Class monikers are monikers that represent an object class. Class monikers bind to the class object of the class for which they are created.

Class monikers are most useful in composition with other types of monikers, such as file monikers or item monikers. Class monikers may also be composed to the right of monikers supporting binding to the IClassActivator interface. This allows IClassActivator to provide access to the class object and instances of the class.

When to Use

To use class monikers, you must use the CreateClassMoniker function to create the monikers.


  • IMoniker::BindToObject
    If pmkLeft is NULL, calls CoGetClassObject, using the CLSID the class moniker was initialized with (in CreateClassMoniker or through MkParseDisplayName) and the CLSCTX of the current pbc (IBindContext).

    If pmkLeft is non-NULL, calls pmkLeft->BindToObject for IClassActivator and calls IClassActivator::GetClassObject with the CLSID it was initialized with and the CLSCTX and LOCALE parameters of the current pbc (IBindContext).

    This process is very roughly sketched out in the following code:

        BIND_OPTS2    bindOpts;
        IClassActivator *pActivate;
        bindOpts.cbStruct = sizeof(bindOpts);
        if (NULL == pmkToLeft)
            return CoGetClassObject(<clsid>, bindOpts.dwClassContext, NULL, riid, ppvResult);
        pmkToLeft->BindToObject(pbc, NULL, IID_IClassActivator, (void **) &pActivate);
        hr = pActivate->GetClassObject(<clsid>, bindOpts.dwClassContext, bindOpts.locale, iid, ppvResult);
        return hr;
  • IMoniker::Reduce
    This method returns MK_S_REDUCED_TO_SELF and passes back the same moniker.
  • IMoniker::ComposeWith
    Follows the contract and behaves like an Item Moniker in that it can return E_INVALIDARG and MK_E_NEEDGENERIC, and so forth.
  • IMoniker::Enum
    This method returns S_OK and sets ppenumMoniker to NULL. May return E_INVALIDARG if ppenumMoniker is an invalid pointer.
  • IMoniker::IsEqual
    This method returns S_OK if pmkOther is a class moniker constructed with the same CLSID information as itself. Otherwise, the method returns S_FALSE. May return E_INVALIDARG if pmkOther is an invalid pointer.
  • IMoniker::Hash
    This method calculates a hash value for the moniker and returns S_OK. May return E_INVALIDARG if pdwHash is an invalid pointer.
  • IMoniker::CommonPrefixWith
    If pmkOtherIsEqual to this moniker, retrieves a pointer to this moniker and returns MK_S_US. If pmkOther is a class moniker but is not equal to this moniker, returns MK_E_NOPREFIX. Otherwise, returns the result of calling MonikerCommonPrefixWith with itself as pmkThis, pmkOther, and ppmkPrefix, which handles the case where pmkOther is a generic composite moniker.
  • IMoniker::GetDisplayName
    The display name for class monikers is of the following form:

    display-name = "CLSID:" string-clsid-no-curly-braces *[";" clsid-options] ":"

    clsid-options = clsid-param "=" value

    clsid-param = none currently defined



  • IMoniker::ParseDisplayName
    This method parses the display name by binding to itself for IParseDisplayName and asking the bound object to parse the display name into a moniker, as follows:

        hr = BindToObject(pbc, pmkToLeft, IID_IParseDisplayName, (void**)&ppdn);
        if (SUCCEEDED(hr)) {
            hr = ppdn->ParseDisplayName(pbc, lpszDisplayName, pchEaten, ppmkOut);
        return hr;

    This method tries to acquire an IParseDisplayName pointer, first by binding to the class factory for the object identified by the moniker and then by binding to the object itself. If either of these binding operations is successful, the file moniker passes the unparsed portion of the display name to the IParseDisplayName::ParseDisplayName method.

    This method returns MK_E_SYNTAX if pmkToLeft is non-NULL.

See Also



Send comments about this topic to Microsoft.