IWMEncAttributes::Remove

Windows Media Encoder SDK banner art

The Remove method removes a specific name-value pair from the collection of user-defined attributes.

Syntax

HRESULT Remove(
  VARIANT  var
);

Parameters

var

[in]  VARIANT containing either the name or index of the attribute to be removed.

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_INVALIDARG 0x80070057 The input parameter does not match a valid string name in the attributes collection.
NS_E_INVALID_INDEX2 0xc00d00d9 The input parameter does not match a valid index in the attributes collection.
NS_E_INVALID_CALL_WHILE_ENCODER_RUNNING 0xC00D1B66 You cannot call this method if the encoder engine is running.

Remarks

The attribute to be removed can be specified either by a string name or an index into the attribute collection. Use the IWMEncAttributes::Add method to add an attribute to the collection. Use the IWMEncAttributes::RemoveAll method to delete all attributes from the collection.

Example Code

#include <windows.h>
#include <comdef.h>                // Includes _bstr_T and _variant_T.
#include <atlbase.h>               // Includes CComBSTR.
#include "wmencode.h"

      // Declare variables.
      HRESULT hr;
      IWMEncoder* pEncoder;
      IWMEncAttributes* pAttr;
      CComBSTR m_bstrName;
      CComVariant m_varValue;
      CComVariant m_varIndex;
      CComVariant m_varRemove;
      long cnt;

      // 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 IWMEncAttributes interface.
if ( SUCCEEDED( hr ) )
{
        hr = pEncoder->get_Attributes( &pAttr );
}

      // Add name-value pairs to the attributes collection.
_bstr_t bName[] =
{
    _bstr_t("Date Created: "),
    _bstr_t("Time Created: "),
    _bstr_t("File Content: ")
};
_variant_t vVal[] =
{
    _variant_t("02/15/2000"),
    _variant_t("13:30:15"),
    _variant_t("multimedia data"),
};

for ( int i = 0; i < 3 && SUCCEEDED(hr); i++ )
{
    hr = pAttr->Add(bName[i],vVal[i]);
}

// Retrieve the name-value pairs from the collection.
if ( SUCCEEDED( hr ) )
{
    hr = pAttr->get_Count(&cnt);
}

for ( i = 0; i < cnt && SUCCEEDED( hr ); i++ )
{
    hr = pAttr->Item(i, &m_bstrName, &m_varValue);
}

// Remove an attribute by name.
if ( SUCCEEDED( hr ) )
{
    m_varRemove = "File Content: ";
    hr = pAttr->Remove(m_varRemove);
}

// Remove an attribute by index.
if ( SUCCEEDED( hr ) )
{
    m_varRemove = 0;
    hr = pAttr->Remove(m_varRemove);
}

// Remove all attributes.
if ( SUCCEEDED( hr ) )
{
    hr = pAttr->RemoveAll();
}

// Release pointers.
if ( pAttr )
{
    pAttr->Release();
    pAttr = NULL;
}

if ( pEncoder )
{
    pEncoder->Release();
    pEncoder = NULL;
}

Requirements

Header: wmencode.h

Library: wmenc.exe

See Also