Microsoft DirectX 9.0

Enumerating Pins

Filters support the IBaseFilter::EnumPins method, which enumerates the pins available on the filter. It returns a pointer to the IEnumPins interface. The IEnumPins::Next method retrieves IPin interface pointers.

The following example shows a function that locates a pin with a given direction (input or output) on a given filter. It uses the PIN_DIRECTION enumeration to specify the pin direction, and the IPin::QueryDirection method to find the direction of each enumerated pin. If this function finds a matching pin, it returns an IPin interface pointer with an outstanding reference count. The caller is responsible for releasing the interface.

IPin *GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir)
{
    BOOL       bFound = FALSE;
    IEnumPins  *pEnum;
    IPin       *pPin;

    HRESULT hr = pFilter->EnumPins(&pEnum);
    if (FAILED(hr))
    {
        return NULL;
    }
    while(pEnum->Next(1, &pPin, 0) == S_OK)
    {
        PIN_DIRECTION PinDirThis;
        pPin->QueryDirection(&PinDirThis);
        if (bFound = (PinDir == PinDirThis))
            break;
        pPin->Release();
    }
    pEnum->Release();
    return (bFound ? pPin : NULL);  
}

This function could easily be modified to return the nth pin with the specified direction, or the nth unconnected pin. (To find out if a pin is connected to another pin, call the IPin::ConnectedTo method.)