Search code examples
c++visual-studio-2010directshow

CoCreateInstance creates empty IBaseFilter for CLSID_WavDest


I am trying to record .wav by using directshow framework in C++ Visual Studio 2010 project. I am following WAV file section of this guide: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375005(v=vs.85).aspx

I have built WavDest.dll, added it to registry, found it in the registry, it can be added as filter in Graphedit. I had unresolved external symbol error for _CLSID_WavDest but had fixed it by including InitGuid.h in my StdAfx.h and by linking the WavDest.lib.

Now I get no errors, program doesn't crash, but I get 0 byte wav file.

Section of code:

res = AddFilterByCLSID(dshow_dev->m_pGraph, CLSID_WavDest, (IBaseFilter **)&dshow_dev->m_pWaveDest, L"WavDest");
res = AddFilterByCLSID(dshow_dev->m_pGraph, CLSID_FileWriter, (IBaseFilter **)&dshow_dev->m_pWaveWriter, L"File Writer");


res = dshow_dev->m_pWaveWriter->QueryInterface(IID_IFileSinkFilter, (void**)&dshow_dev->m_pFileSink);
res = dshow_dev->m_pFileSink->SetFileName(L"D:\\test.wav", NULL);

res = ConnectFilters(dshow_dev->m_pGraph, dshow_dev->m_pCaptureSourceAudio, dshow_dev->m_pWaveDest);
res = ConnectFilters(dshow_dev->m_pGraph, dshow_dev->m_pWaveDest, dshow_dev->m_pWaveWriter);

AddFilterByCLSID for CLSID_WavDest returns S_OK but dshow_dev->m_pWaveDest has following values: -

[CWavDestFilter]    {m_cbWavData=0x00000000 m_cbHeader=0x00000000 } CWavDestFilter

.

Therefore, ConnectFilters for m_pWaveDest returns E_Fail and no audio is recorded.

I have tried this with both Debug and Release versions of WavDest.dll registered (first Debug, then unreg Debug and reg Release).

I have checked everything other in code, graph (dshow_dev->m_pGraph) runs fine for video preview and writing AVI file (with audio).

I am sure that that I did something wrong with WavDest integration but I don't know what.

Any help is appreciated.


Solution

  • It was my mistake after all. I have replaced

    assert(pResult != NULL);
    

    in this function

    // Match a pin by pin direction and connection state.
    HRESULT MatchPin(IPin *pPin, PIN_DIRECTION direction, BOOL bShouldBeConnected, BOOL *pResult)
    {
        assert(pResult != NULL);
    
        BOOL bMatch = FALSE;
        BOOL bIsConnected = FALSE;
    
        HRESULT hr = IsPinConnected(pPin, &bIsConnected);
        if (SUCCEEDED(hr))
        {
            if (bIsConnected == bShouldBeConnected)
            {
                hr = IsPinDirection(pPin, direction, &bMatch);
            }
        }
    
        if (SUCCEEDED(hr))
        {
            *pResult = bMatch;
        }
        return hr;
    }
    

    with

    if(pResult == NULL);
    {
        HRESULT hr = E_FAIL;
        return hr;
    }