# 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.

Remarks

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 from 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);
        pbc->GetBindOptions(&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);
        pActivate->Release();
        return hr;

IMoniker::BindToStorage
  This method forwards to the class moniker’s BindToObject.
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, etc.
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::IsRunning
  Returns E_NOTIMPL.
IMoniker::GetTimeOfLastChange
  Returns MK_E_UNAVAILABLE.
IMoniker::Inverse
  This method returns an anti-moniker (i.e., the results of calling CreateAntiMoniker).
IMoniker::CommonPrefixWith
  If pmkOther IsEqual to this moniker, retrives 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 whre pmkOther is a generic composite moniker.
IMoniker::RelativePathTo
  This method returns the result of calling This method returns the result of calling MonikerRelativePathTo with pmkSrc equal to this moniker, pmkOther, ppmkRelPath, and TRUE as dwReserved.
IMoniker::GetDisplayName
  The display name for class monikers is of the form:

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

  clsid-options = clsid-param “=“ value

  clsid-param = none currently defined

  Example:

  clsid:a7b90590-36fd-11cf-857d-00aa006d2ea4:

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);
            ppdn->Release();
            }
        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.

- IMoniker::IsSystemMoniker

  This method returns S_OK, and passes back MKSYS_CLASSMONIKER.

See Also

CreateClassMoniker, IMoniker