L_TwainGetDeviceEventCapability

#include "lttwn.h"

L_LTTWN_API L_INT L_TwainGetDeviceEventCapability (hSession, pDeviceCap)

HTWAINSESSION hSession;

/* handle to an existing TWAIN session */

pTW_CAPABILITY pDeviceCap;

/* pointer to a structure */

Gets the device event capability (CAP_DEVICEEVENT) values for the current TWAIN session.

Parameter

Description

hSession

Handle to an existing TWAIN session. This handle is obtained by calling the L_TwainInitSession function.

pDeviceCap

Pointer to a TW_CAPABILITY structure that references the required device event capability. This structure must be allocated and it will be filled with data corresponding to the required capability to get.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

To set the CAP_DEVICEEVENT capability value, call L_TwainSetDeviceEventCapability function.

To rest the CAP_DEVICEEVENT capability value to the default, call L_TwainResetDeviceEventCapability function.

To get the status for each device event, call L_TwainSetDeviceEventCallback function.

To get the device event information, call L_TwainGetDeviceEventData function.

This function should be called after calling L_TwainStartCapsNeg function and before calling L_TwainEndCapsNeg function.

Required DLLs and Libraries

LTTWN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_TwainStartCapsNeg, L_TwainSetDeviceEventCallback, L_TwainGetDeviceEventData, L_TwainSetDeviceEventCapability, L_TwainResetDeviceEventCapability, LTWAINDEVICEEVENTCALLBACK

Topics:

Getting and Setting Capabilities

 

TWAIN Functionality: Capability Functions

Example

 L_INT GetDeviceEventCapabilityExample(HTWAINSESSION hSession)
{
   L_INT nRet = SUCCESS;
   TW_CAPABILITY twCap;

   memset(&twCap, 0, sizeof(TW_CAPABILITY));

   L_TwainStartCapsNeg(hSession);
   nRet = L_TwainGetDeviceEventCapability(hSession, &twCap);
   if (nRet != SUCCESS)
      return nRet;

   if (twCap.Cap == CAP_DEVICEEVENT)
   {
      pTW_ARRAY ptwArray = (pTW_ARRAY)GlobalLock(twCap.hContainer);
      int count = ptwArray->NumItems;
      for (int i = 0; i < count; i++)
      {
         pTW_UINT16 ptwItems = (pTW_UINT16)ptwArray->ItemList;
         TW_UINT16 capValue = ptwItems[i];

         switch (capValue)
         {
         case TWDE_CHECKBATTERY:
            MessageBox(NULL, TEXT("Device event checks the battery"), TEXT("Notice!"), MB_OK);
            break;
         case TWDE_CHECKRESOLUTION:
            MessageBox(NULL, TEXT("Device event checks the resolution"), TEXT("Notice!"), MB_OK);
            break;
         case TWDE_DEVICEREADY:
            MessageBox(NULL, TEXT("Device event is ready"), TEXT("Notice!"), MB_OK);
            break;
         }
      }
      GlobalUnlock(twCap.hContainer);
      GlobalFree(twCap.hContainer);

      memset(&twCap, 0, sizeof(TW_CAPABILITY));
      twCap.Cap = CAP_DEVICEEVENT;
      twCap.ConType = TWON_ARRAY;
      twCap.hContainer = (TW_HANDLE)GlobalAlloc(GHND, sizeof(TW_ARRAY)+ sizeof(TW_UINT16) * 5);
      ptwArray = (pTW_ARRAY)GlobalLock(twCap.hContainer);

      ptwArray->ItemType = TWTY_UINT16;
      ptwArray->NumItems = 5;
      TW_UINT16 twItems[5];
      twItems[0] = TWDE_DEVICEREADY;
      twItems[1] = TWDE_CHECKDEVICEONLINE;
      twItems[2] = TWDE_CHECKBATTERY;
      twItems[3] = TWDE_CHECKPOWERSUPPLY;
      twItems[4] = TWDE_CHECKRESOLUTION;

      memcpy((void *)&ptwArray->ItemList, twItems, sizeof(TW_UINT16)*5);
      GlobalUnlock(twCap.hContainer);
      nRet = L_TwainSetDeviceEventCapability(hSession, &twCap);
      if (nRet == SUCCESS)
         MessageBox(NULL, TEXT("DeviceEvent is changed successfully"), TEXT("Notice!"), MB_OK);
      nRet = L_TwainResetDeviceEventCapability(hSession, &twCap);
      if (nRet == SUCCESS)
         MessageBox(NULL, TEXT("DeviceEvent is reset to default values successfully"), TEXT("Notice!"), MB_OK);
   }

   L_TwainEndCapsNeg(hSession);

   return SUCCESS;
}