ISoftUSBConfigurations::Add Method

The Add method adds an object to a collection of SoftUSBConfiguration objects.

Syntax

HRESULT Add(
  [in]            SOFTUSBConfiguration *pSOFTUSBConfig,
  [in, optional]  VARIANT Index
);

Parameters

  • pSOFTUSBConfig [in]
    A pointer to a SoftUSBConfiguration co-class to add to the collection.

  • Index [in, optional]
    The index where Add will store the SoftUSBConfiguration co-class. Add fails if the caller tries to add an item to an index that is already occupied.

    If the caller does not specify an index, the SoftUSBConfiguration co-class is added at the default location, which is the first empty entry in the list. For more information about how to not specify an index, see article Q238981 "How to pass optional parameters when you call a function in Visual C++" in the Microsoft Knowledge Base.

Return Value

Add returns one of the following HRESULT values:

Return code Description
S_OK

The SoftUSBConfiguration co-class was correctly added to the collection.

E_INVALIDARG

The pSOFTUSBConfig pointer is not valid.

 

Remarks

The following C++ code example shows how to add an ISoftUSBConfiguration to the collection by not specifying an index. This example uses the C++ convention for passing optional parameters.

HRESULT CTestDevice:: AddConfig(ISoftUSBConfiguration *piConfig)
{
HRESULT  hr = S_OK;
ISoftUSBConfigurations *piConfigList = NULL; 
VARIANT  varOpt;

// Get the configuration list      
hr = m_piUSBDevice->get_Configurations(&piConfigList); 
if (!FAILED(hr))
{  
 varOpt.vt = VT_ERROR;
   varOpt.scode = DISP_E_PARAMNOTFOUND;

 hr = piConfigList->Add(reinterpret_cast<SoftUSBConfiguration*>(piConfig),  varOpt);
}

if(NULL != piConfigList)
{     
 piConfigList->Release();     
 piConfigList = NULL;
}

return hr;
}

The following C++ code example shows how to add an ISoftUSBConfiguration to the collection by using a specific index.

HRESULT CTestDevice:: AddConfig(ISoftUSBConfiguration *piConfig)
{
HRESULT  hr = S_OK;
ISoftUSBConfigurations *piConfigList = NULL; 
VARIANT  varIndex; 

// Get the configuration list      
hr = m_piUSBDevice->get_Configurations(&piConfigList); 
if (!FAILED(hr))
{  
 // Initialize VARIANT Index
   ::VariantInit(&varIndex); 
 varIndex.vt = VT_I4;
 varIndex.lVal = 1

 hr = piConfigList->Add(reinterpret_cast<SoftUSBConfiguration*>(piConfig),  varIndex);
}

if(NULL != piConfigList)
{     
 piConfigList->Release();     
 piConfigList = NULL;
}

return hr;
}

Requirements

Header

SoftUSBif.h

 

 

Send comments about this topic to Microsoft

Build date: 9/21/2010