Yes of course

Debbuging the code I can see that the
HRESULT hr = pFilter->EnumPins(&pEnum);
in GetPin() is ok (pFilter is NOT null).
But the following
while(pEnum->Next(1, &pPin, 0) == S_OK)
fails immediately.
Here is the generated code... Thank you very much.
//Don't forget to change project settings:
//1. C++: add include path to DirectShow include folder (such as c:\dxsdk\include)
//2. Link: add link path to DirectShow lib folder (such as c:\dxsdk\lib).
//3. Link: add strmiids.lib and quartz.lib
#include "stdafx.h"
#include <DShow.h>
#include <atlbase.h>
#include <initguid.h>
#include <dvdmedia.h>
BOOL hrcheck(HRESULT hr, TCHAR* errtext)
{
if (hr >= S_OK)
return FALSE;
TCHAR szErr[MAX_ERROR_TEXT_LEN];
DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
if (res)
printf("Error %x: %s\n%s\n",hr, errtext,szErr);
else
printf("Error %x: %s\n", hr, errtext);
return TRUE;
}
//change this macro to fit your style of error handling
#define CHECK_HR(hr, msg) if (hrcheck(hr, msg)) return hr;
CComPtr<IPin> GetPin(IBaseFilter *pFilter, LPCOLESTR pinname)
{
CComPtr<IEnumPins> pEnum;
CComPtr<IPin> pPin;
HRESULT hr = pFilter->EnumPins(&pEnum);
if (hrcheck(hr, "Can't enumerate pins."))
return NULL;
while(pEnum->Next(1, &pPin, 0) == S_OK)
{
PIN_INFO pinfo;
pPin->QueryPinInfo(&pinfo);
BOOL found = !wcsicmp(pinname, pinfo.achName);
if (pinfo.pFilter) pinfo.pFilter->Release();
if (found)
return pPin;
pPin.Release();
}
printf("Pin not found!\n");
return NULL;
}
// {17CCA71B-ECD7-11D0-B908-00A0C9223196}
DEFINE_GUID(CLSID_MicrosoftDVCameraandVCR,
0x17CCA71B, 0xECD7, 0x11D0, 0xB9, 0x08, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //ksproxy.ax
// {B87BEB7B-8D29-423F-AE4D-6582C10175AC}
DEFINE_GUID(CLSID_VideoRenderer,
0xB87BEB7B, 0x8D29, 0x423F, 0xAE, 0x4D, 0x65, 0x82, 0xC1, 0x01, 0x75, 0xAC); //quartz.dll
HRESULT BuildGraph(IGraphBuilder *pGraph)
{
HRESULT hr = S_OK;
//graph builder
CComPtr<ICaptureGraphBuilder2> pBuilder;
hr = pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2);
CHECK_HR(hr, "Can't create Capture Graph Builder");
hr = pBuilder->SetFiltergraph(pGraph);
CHECK_HR(hr, "Can't SetFiltergraph");
//add Microsoft DV Camera and VCR
CComPtr<IBaseFilter> pMicrosoftDVCameraandVCR;
hr = pMicrosoftDVCameraandVCR.CoCreateInstance(CLSID_MicrosoftDVCameraandVCR);
CHECK_HR(hr, "Can't create Microsoft DV Camera and VCR");
hr = pGraph->AddFilter(pMicrosoftDVCameraandVCR, L"Microsoft DV Camera and VCR");
CHECK_HR(hr, "Can't add Microsoft DV Camera and VCR to graph");
//add DV Splitter
CComPtr<IBaseFilter> pDVSplitter;
hr = pDVSplitter.CoCreateInstance(CLSID_DVSplitter);
CHECK_HR(hr, "Can't create DV Splitter");
hr = pGraph->AddFilter(pDVSplitter, L"DV Splitter");
CHECK_HR(hr, "Can't add DV Splitter to graph");
//connect Microsoft DV Camera and VCR and DV Splitter
hr = pGraph->ConnectDirect(GetPin(pMicrosoftDVCameraandVCR, L"DV A/V Out"), GetPin(pDVSplitter, L"Input"), NULL);
CHECK_HR(hr, "Can't connect Microsoft DV Camera and VCR and DV Splitter");
//add DirectSound: Altoparlanti (Realtek High Definition Audio)
CComPtr<IBaseFilter> pDirectSoundAltoparlantiRealtekHighDefinitionAudio;
hr = pDirectSoundAltoparlantiRealtekHighDefinitionAudio.CoCreateInstance(CLSID_DSoundRender);
CHECK_HR(hr, "Can't create DirectSound: Altoparlanti (Realtek High Definition Audio)");
hr = pGraph->AddFilter(pDirectSoundAltoparlantiRealtekHighDefinitionAudio, L"DirectSound: Altoparlanti (Realtek High Definition Audio)");
CHECK_HR(hr, "Can't add DirectSound: Altoparlanti (Realtek High Definition Audio) to graph");
//add DV Video Decoder
CComPtr<IBaseFilter> pDVVideoDecoder;
hr = pDVVideoDecoder.CoCreateInstance(CLSID_DVVideoCodec);
CHECK_HR(hr, "Can't create DV Video Decoder");
hr = pGraph->AddFilter(pDVVideoDecoder, L"DV Video Decoder");
CHECK_HR(hr, "Can't add DV Video Decoder to graph");
//connect DV Splitter and DV Video Decoder
hr = pGraph->ConnectDirect(GetPin(pDVSplitter, L"DVVidOut0"), GetPin(pDVVideoDecoder, L"XForm In"), NULL);
CHECK_HR(hr, "Can't connect DV Splitter and DV Video Decoder");
//connect DV Splitter and DirectSound: Altoparlanti (Realtek High Definition Audio)
hr = pGraph->ConnectDirect(GetPin(pDVSplitter, L"AudOut00"), GetPin(pDirectSoundAltoparlantiRealtekHighDefinitionAudio, L"Audio Input pin (rendered)"), NULL);
CHECK_HR(hr, "Can't connect DV Splitter and DirectSound: Altoparlanti (Realtek High Definition Audio)");
//add Video Renderer
CComPtr<IBaseFilter> pVideoRenderer;
hr = pVideoRenderer.CoCreateInstance(CLSID_VideoRenderer);
CHECK_HR(hr, "Can't create Video Renderer");
hr = pGraph->AddFilter(pVideoRenderer, L"Video Renderer");
CHECK_HR(hr, "Can't add Video Renderer to graph");
//connect DV Video Decoder and Video Renderer
hr = pGraph->ConnectDirect(GetPin(pDVVideoDecoder, L"XForm Out"), GetPin(pVideoRenderer, L"VMR Input0"), NULL);
CHECK_HR(hr, "Can't connect DV Video Decoder and Video Renderer");
return S_OK;
}
//int _tmain(int argc, _TCHAR* argv[]) //use this line in VS2008
int main(int argc, char* argv[])
{
CoInitialize(NULL);
CComPtr<IGraphBuilder> graph;
graph.CoCreateInstance(CLSID_FilterGraph);
printf("Building graph...\n");
HRESULT hr = BuildGraph(graph);
if (hr==S_OK) {
printf("Running");
CComQIPtr<IMediaControl, &IID_IMediaControl> mediaControl(graph);
hr = mediaControl->Run();
CHECK_HR(hr, "Can't run the graph");
CComQIPtr<IMediaEvent, &IID_IMediaEvent> mediaEvent(graph);
BOOL stop = FALSE;
MSG msg;
while(!stop)
{
long ev=0, p1=0, p2=0;
Sleep(500);
printf(".");
while(PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
DispatchMessage(&msg);
while (mediaEvent->GetEvent(&ev, &p1, &p2, 0)==S_OK)
{
if (ev == EC_COMPLETE || ev == EC_USERABORT)
{
printf("Done!\n");
stop = TRUE;
}
else
if (ev == EC_ERRORABORT)
{
printf("An error occured: HRESULT=%x\n", p1);
mediaControl->Stop();
stop = TRUE;
}
mediaEvent->FreeEventParams(ev, p1, p2);
}
}
}
CoUninitialize();
return 0;
}