SetCapability Example for C++ 5.0 and later

ILEADRasterTwain_U * pRasterTwain;
short iRet; 
ICapability_U * pCapability = NULL; 
ICapabilityOneValue_U * pCapOV = NULL; 

HRESULT hr = ::CoCreateInstance(CLSID_LEADRasterTwain_U, NULL, CLSCTX_ALL, IID_ILEADRasterTwain_U, (void **)&pRasterTwain);
if (FAILED(hr) || !pRasterTwain)
{
	::MessageBox (NULL, _TEXT("Failed to create a Raster Twain Object"), _TEXT("Error"), MB_OK);
	return;
}

pRasterTwain->InitSession((long)GetSafeHwnd()); 
pRasterTwain->SelectSource();

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

pCapability->put_EnableMethodErrors(VARIANT_FALSE); 
pCapability->ConType = L_TWON_DONTCARE16; 
pCapability->Capability = L_ICAP_UNITS; 
iRet = pRasterTwain->GetCapability(pCapability, L_LTWAIN_CAPABILITY_GETCURRENT); 

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

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

//Set the units to inches
pCapability->put_Capability(L_ICAP_UNITS); 
pCapability->put_ConType (L_TWON_ONEVALUE); 

ILEADRasterVariant_U * CapVal = NULL; 
CoCreateInstance(CLSID_LEADRasterVariant_U, NULL, CLSCTX_ALL, 
							   IID_ILEADRasterVariant_U, (void **)&CapVal); 

CapVal->Type = VALUE_USHORT; 
CapVal->LongValue = L_TWUN_INCHES; 

pCapOV->put_OneValItemType (L_TWTY_UINT16); 
pCapOV->put_OneValCapValue (CapVal); 

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

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