SetCapability Example for C++ 5.0 and later

ILEADRasterTwain * m_pltRasTwain; 
void TestSetCapability()
{
   short iRet; 
   HRESULT hr; 
   ICapability * pCapability = NULL; 
   ICapabilityOneValue * pCapOV = NULL; 

   hr = ::CoCreateInstance (CLSID_LEADRasterTwainCapability, NULL, CLSCTX_ALL, IID_ICapability, (void **)&pCapability); 
   if (FAILED (hr) || pCapability == NULL) 
      return; 

   pCapability->put_
EnableMethodErrors(VARIANT_FALSE); 

   pCapability->
ConType = L_TWON_DONTCARE16; 
   pCapability->
Capability = L_ICAP_UNITS; 
   iRet = m_pltRasTwain->
GetCapability(pCapability, L_LTWAIN_CAPABILITY_GETCURRENT); 

   if (iRet != 0) 
      MessageBox(NULL, 
TEXT("Error Getting Capability"), NULL, MB_OK);

   pCapability->QueryInterface (IID_ICapabilityOneValue, (void **)&pCapOV); 
   if (!pCapOV) 
   {
      pCapability->Release ();
      return; 
   }

   pCapability->put_
Capability(L_ICAP_UNITS); 
   pCapability->put_
ConType (L_TWON_ONEVALUE); 

   ILEADRasterVariant * CapVal = NULL; 
   CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL, 
                                   IID_ILEADRasterVariant, (void **)&CapVal); 

   CapVal->Type = VALUE_USHORT; 
   CapVal->LongValue = L_TWUN_INCHES; 
   
   pCapOV->put_
OneValItemType (L_TWTY_UINT16); 
   pCapOV->put_
OneValCapValue (CapVal); 

   iRet = m_pltRasTwain->
SetCapability (pCapability, L_LTWAIN_CAPABILITY_SET); 

   pCapOV->Release ();
   pCapability->Release ();
   CapVal->Release();
   
}