IMoniker::IsRunning

HRESULT IMoniker::IsRunning(pbc, pmkToLeft, pmkNewlyRunning)

Answer as to whether this moniker is in fact running. As usual, the Running Object Table in whose context this question is to be answered is obtained by this moniker from the Bind context. pmkToLeft is the moniker to the left of this object in the generic composite in which it is found, if any.

If non-NULL, pmkNewlyRunning is the moniker which has most recently been added to the Running Object Table; the implementation of IMoniker::IsRunning can assume that without this object in the Running Object Table, that IMoniker::IsRunning would have reported that it was not running; thus, the only way that it can now be running is if this newly running moniker is in fact itself! This allows for some n[squared]-to-n reductions in algorithms that use monikers. (If the moniker implementation chose to ignore pmkNewlyRunning, no harm would come: this moniker is in fact in the Running Object Table)

Implementations of this method in various kinds of moniker classes are roughly as follows:

Generic Composite Moniker:


if (pmkToLeft != NULL)
    return (pmkToLeft->ComposeWith(this)) -> IsRunning(pbc, NULL, pmkNewlyRunning);
if (pmkNewlyRunning != NULL) {
    if (pmkNewlyRunning -> IsEqual(this) == NOERROR)
        return NOERROR;
    }
else if (pRunningObjectTable -> IsRunning(this) == NOERROR)
    return NOERROR;
// otherwise, forward it on to my last element.
return this->Last()->IsRunning(pbc, this->AllButLast(), pmkNewlyRunning)

Any moniker whose class does not do any wildcard matching.


if (pmkToLeft == NULL) {
    if (pmkNewlyRunning != NULL)
        return pmkNewlyRunning -> IsEqual(this);
    else
        return pRunningObjectTable -> IsRunning(this);
    }
else
    return ResultFromScode(S_FALSE);    // If I was running, then Generic Composite would have caught it.

A moniker class which has a wild card entry which always matches any instance of the moniker class: if the wild card is present, then all instances of the moniker class to the right of the same other moniker (that is, with the same moniker to their left) are deemed to be running. Such a moniker class might be reasonably used, for example, to match all the addressable ranges in a given spreadsheet.


if (pmkToLeft == NULL) {
    if (pmkNewlyRunning != NULL)
        return pmkNewlyRunning->IsEqual(this) == NOERROR 
            || pmkNewlyRunning->IsEqual(my wild card moniker) == NOERROR;
    if (pRunningObjectTable -> IsRunning(this) == NOERROR)
        return NOERROR;
    return pRunningObjectTable -> IsRunning(my wild card moniker);
    }
else 
    return pmkToLeft->ComposeWith(my wild card moniker) -> IsRunning(pbc, NULL, pmkNewlyRunning);

A moniker class which has a wild card entry which matches against some of the objects, but only the ones which are in fact actually currently running. We illustrate here specifically the behaviour of Item Monikers.


if (pmkToLeft == NULL) {
    if (pmkNewlyRunning != NULL) {
        if (pmkNewlyRunning->IsEqual(this) == NOERROR)
            return NOERROR;
        if (pmkNewlyRunning->IsEqual(my wild card moniker) != NOERROR)
            return ResultFromScode(S_FALSE);
        goto TestBind:
        }
    }
if (pmkToLeft->ComposeWith(my wild card moniker)->IsRunning(pbc, NULL, pmkNewlyRunning) != NOERROR)
    return ResultFromScode(S_FALSE);
TestBind:
// In general, connect to the container and ask whether the object is running. The use of 
// IOleItemContainer here is Item Moniker-specific, but the theme is a general one.
IOleItemContainer *pcont;
pmkToLeft->BindToObject(pbc, NULL, IID_IOleItemContainer, &pcont);
return pcont->IsRunning(szItemString);

The arguments to this function are as follows:

Argument

Type

Description

pbc

IBindCtx*

The usual bind context.

pmkToLeft

IMoniker*

The moniker to the left of this one in the composite in which it is found.

pmkNewlyRunning

IMoniker*

May be NULL. If non-NULL, then this is the moniker which has been most recently added to the Running Object Table. In this case, IMoniker::IsRunning implementations may assume that without this moniker in the R.O.T. that IMoniker::IsRunning would return S_FALSE.

return value

HRESULT

S_OK, S_FALSE