int max( int a, int b){if ( a>b) return a; else return b;} 是从结果返回
//下边这个函数是从参数返回
HRESULT GetUnconnectedPin(
IBaseFilter *pFilter, //pointer to the filter
PIN_DIRECTION PinDir, //Direction of the pin to find
IPin ** ppPin) //Receive a pointer to the pin (input pin)
/*上边函数中 pin 的方向,决定了另外两个参数的特点,如果是输入pin,那么filter就是要下一级的filter,而pin就是输入pin;如果direction是output,那么filter就是上一级的filter,而pin也是上一级的outputpin
{
*ppPin = 0;
IEnumPins *pEnum = 0;
IPin *pPin = 0; // use for test the pin
HRESULT hr = pFilter->EnumPins(&pEnum);
if(FAILED(hr))
{
return hr;
}
while(pEnum->Next(1,&pPin,NULL) == S_OK)
{
PIN_DIRECTION ThisPinDir; //the next pin's direction
pPin->QueryDirection(&ThisPinDir);
if(ThisPinDir = PinDir) //it is just what we seek
{
IPin *pTmp = 0; //use for test the pin is connected or not
hr = pPin->ConnectedTo(&pTmp); //取和pPin连接的pin放到指针pTmp中
if(SUCCEEDED(hr))
{
pTmp->Release();
}
else
{
pEnum->Release();
*ppPin = pPin; //the pointer which will return
return S_OK;
}
}
pPin->Release();
}
return E_FAIL;
}
//filter is different from the pin
// queryinterface is used by filter
// querydirection is used by pin
/*
pTmp不是测试pin 为了测试pPin是否链接了 因为要求是没链接的 用Pin->ConnectedTo(&pTmp);取和pPin链接的Pin放到pTmp里
如果pin已经链接了 函数会成功 那么pPin不符合要求 释放pTmp 继续枚举
如果函数失败 说明pPin没链接 符合要求 就返回了
*/