IWMEncDeviceControlCollection::Remove
![]() |
The Remove method removes a specific device control object from the collection.
Syntax
HRESULT Remove(
long lIndex
);
Parameters
lIndex
[in] long containing the index of the object to remove.
Return Values
If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.
Remarks
Use the get_Count method to retrieve the number of objects in the device control collection.
Example Code
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"
#include "C:\WMSDK\WMEncSDK9\include\wmdevctl.h"
// Declare variables.
HRESULT hr;
IWMEncoder2* pEncoder;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSourceGroup2* pSrcGrp2;
IWMEncSource* pSrcAud;
IWMEncSource* pSrcVid;
IWMEncDeviceControlCollection* pDCColl;
IWMEncDeviceControl* pDControl;
// 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_IWMEncoder2,
(void**) &pEncoder);
}
// Retrieve the source group collection.
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);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->QueryInterface(IID_IWMEncSourceGroup2, (void**)&pSrcGrp2);
}
// Add an audio and a video source to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrcVid);
}
// Add the device as the audio source and video source.
if ( SUCCEEDED( hr ) )
{
hr = pSrcAud->SetInput(CComBSTR("Device://DEVICENAME"));
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://DEVICENAME"));
}
// Retrieve the device control collection, then add a device to it.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp2->get_DeviceControlCollection(&pDCColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pDCColl->Add(&pDControl);
}
if ( SUCCEEDED( hr ) )
{
hr = pDControl->SetInput(CComBSTR("DeviceControl://DEVICENAME"));
}
// Retrieve the number of devices in the collection.
long lCount;
if ( SUCCEEDED( hr ) )
{
hr = pDCColl->get_Count(&lCount);
}
// Retrieve the first device.
if ( SUCCEEDED( hr ) )
{
hr = pDCColl->Item(0, &pDControl);
}
// Remove the first device from the collection.
if ( SUCCEEDED( hr ) )
{
hr = pDCColl->Remove(0);
}
// Release pointers.
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pSrcGrp2 )
{
pSrcGrp2->Release();
pSrcGrp2 = NULL;
}
if ( pSrcAud )
{
pSrcAud->Release();
pSrcAud = NULL;
}
if ( pSrcVid )
{
pSrcVid->Release();
pSrcVid = NULL;
}
if ( pDCColl )
{
pDCColl->Release();
pDCColl = NULL;
}
if ( pDControl )
{
pDControl->Release();
pDControl = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
Requirements
Header: wmdevctl.h
Library: wmdevctl.dll
See Also
.gif)