IWMEncDataViewCollection::get_Count

Windows Media Encoder SDK banner art

The get_Count method retrieves the number of IWMEncDataView objects in the collection.

Syntax

HRESULT get_Count(
  long*  plCount
);

Parameters

plCount

[out]  Pointer to a long containing the number of objects.

Return Values

If the method succeeds, it returns S_OK. If it fails, it supports an IErrorInfo interface and returns an HRESULT error code.

Return code Number Description
E_POINTER 0x80004003 The pointer to the data view object count is NULL.

Example Code

// Include libraries.

#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"
#include "wmencvu.h"

// Declare variables.

    HRESULT hr;
    IWMEncoder* pEncoder;
    IUnknown* pPreview;
    IWMEncDataView* pPreview_1;
    IWMEncDataView* pPreview_2;
    IWMEncDataView* pPreview_3;
    IWMEncDataViewCollection* pPreviewColl;
    IWMEncSourceGroupCollection* pSrcGrpColl;
    IWMEncSourceGroup* pSrcGrp;
    IWMEncSource* pAudSrc;
    IWMEncSource* pVidSrc;

    long lCount, lCookie, i, lDataViewIndex;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance(CLSID_WMEncoder,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_IWMEncoder,
                          (void**) &pEncoder);
}

// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.

if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}

// Add a source group to the collection.

if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}

// Add a video and an audio source to the source group.

if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}
if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}

// Create three preview objects and return pointers.

if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance( CLSID_WMEncPreview,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_IWMEncDataView,
                           (void**)&pPreview_1);
}

if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance( CLSID_WMEncPreview,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_IWMEncDataView,
                           (void**)&pPreview_2);
}

if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance( CLSID_WMEncPreview,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_IWMEncDataView,
                           (void**)&pPreview_3);
}

// Retrieve the preview collection.

if ( SUCCEEDED( hr ) )
{
    hr = pVidSrc->get_PreviewCollection( &pPreviewColl );
}

// Add the preview objects to the data view collection. If you set the
// cookie to -1, the encoding process automatically generates a unique
// cookie.

long lCookie_1 = -1;
if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->Add( pPreview_1, &lCookie_1);
}

long lCookie_2 = -1;
if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->Add( pPreview_2, &lCookie_2);
}

long lCookie_3 = -1;
if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->Add( pPreview_3, &lCookie_3);
}

// Retrieve the cookies for each preview.

if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->get_Count(&lCount);
}

for (i=0; i<lCount; i++)
{
    if ( SUCCEEDED( hr ) )
    {
        hr = pPreviewColl->Item(i, &pPreview, &lCookie);
    }
}

// Remove the second preview object from the collection.
// The index is zero-based.

lDataViewIndex = 1;
if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->Remove(lDataViewIndex);
}

// Remove the remaining cookies from the collection.

if ( SUCCEEDED( hr ) )
{
    hr = pPreviewColl->RemoveAll();
}

// Release pointers.
if ( pEncoder )
{
    pEncoder->Release();
    pEncoder = NULL;
}
if ( pPreview )
{
    pPreview->Release();
    pPreview = NULL;
}
if ( pPreviewColl )
{
    pPreviewColl->Release();
    pPreviewColl = NULL;
}
if ( pSrcGrpColl )
{
    pSrcGrpColl->Release();
    pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
    pSrcGrp->Release();
    pSrcGrp = NULL;
}
if ( pAudSrc )
{
    pAudSrc->Release();
    pAudSrc = NULL;
}
if ( pVidSrc )
{
    pVidSrc->Release();
    pVidSrc = NULL;
}
if ( pPreview_1 )
{
    pPreview_1->Release();
    pPreview_1 = NULL;
}
if ( pPreview_2 )
{
    pPreview_2->Release();
    pPreview_2 = NULL;
}
if ( pPreview_3 )
{
    pPreview_3->Release();
    pPreview_3 = NULL;
}

Requirements

Header: wmencvu.h

Library: wmprevu.dll

See Also