L_TwainAcquire

#include "lttw2.h"

L_INT EXT_FUNCTION L_TwainAcquire (hSession, pBitmap, uStructSize, pfnCallBack, uFlags, lpszTemplateFile, pUserData)

HTWAINSESSION hSession;

/* handle to an existing TWAIN session */

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UINT uStructSize;

/* size in bytes, of the structure pointed to by pBitmap */

LTWAINBITMAPCALLBACK pfnCallBack;

/* callback function */

L_UINT uFlags;

/* optional flags */

L_TCHAR * lpszTemplateFile;

/* template file name */

L_VOID * pUserData;

/* pointer to more parameters for the callback */

Acquires one or more images from a TWAIN source.

Parameter

Description

hSession

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

pBitmap

Pointer to the bitmap handle that references the last bitmap acquired from the TWAIN source.

uStructSize

Size in bytes, of the structure pointed to by pBitmap, for versioning. Use sizeof(BITMAPHANDLE).

pfnCallBack

Optional callback function for multipage scanning. Use NULL as the value of this parameter if you are processing only one image. If you provide a callback function, use the function pointer as the value of this parameter.

 

L_TwainAcquire calls this callback function as it acquires each page into the bitmap. The callback function must adhere to the following function prototype: LTWAINBITMAPCALLBACK.

uFlags

Flag that determines certain actions of the TWAIN source. Possible values are:

 

Value

Meaning

 

0

Do not show the manufacturer's user interface.

 

LTWAIN_SHOW_USER_INTERFACE

[0x0001] Shows the manufacturer's user interface as modeless.

 

LTWAIN_MODAL_USER_INTERFACE

[0x0002] Shows the manufacturer's user interface as a modal dialog. Works only if the LTWAIN_SHOW_USER_INTERFACE flag is set.

 

LTWAIN_KEEPOPEN

[0x0020] Keep the TWAIN data source open after scanning.

lpszTemplateFile

Character string that contains the name of the template file in which the TWAIN source capability settings will be saved. If this parameter is NULL, the TWAIN capability settings used will not be saved to a template file. For more information on determining/setting the capabilities for a TWAIN source, refer to Getting and Setting Capabilities.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

! = SUCCESS

An error occurred. Refer to Return Codes.

Comments

When acquiring multiple pages, the LTWAINBITMAPCALLBACK callback function receives the scanned images through the pBitmap parameter. The user can then process these images as desired within the callback function.

When acquiring a single page, pass NULL for the pfnCallBack parameter. The pBitmap is updated with the single scanned image.

The number of pages to acquire can be determined by getting the TWAIN source's capabilities. To change the number of pages to acquire, set the appropriate capability to the desired number.

To cancel the acquire operation call the L_TwainCancelAcquire.

To stop acquire images only from the feeder of the TWAIN source, call the L_TwainStopFeeder 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_TwainAcquireList, L_TwainInitSession, L_TwainEndSession, L_TwainOpenTemplateFile, L_TwainCloseTemplateFile, L_TwainTemplateDlg, L_TwainAddCapabilityToFile, L_TwainGetNumofCapsInFile, L_TwainGetCapabilityFromFile, L_TwainCancelAcquire, L_TwainStopFeeder

Topics:

How to Acquire from the TWAIN Source

 

TWAIN Functionality: Property Functions.

Example

HTWAINSESSION g_hSession;

L_INT EXT_CALLBACK BmpCB (HTWAINSESSION hSession, pBITMAPHANDLE pBitmap, L_VOID * pUserData)
{
   // You can do here any processing to the bitmap

   return SUCCESS;
}

void TwainAcquire (pBITMAPHANDLE pBitmap) 
{
   L_INT nRet; 
   TW_CAPABILITY twCap;

   // Show the Twain Select Source UI
   nRet = L_TwainSelectSource(g_hSession, NULL);
   if (nRet != SUCCESS) 
      MessageBox (NULL, TEXT("Error occurred while selecting the source."),TEXT( "ERROR"), MB_OK); 

   L_TwainStartCapsNeg(g_hSession);

   twCap.Cap = ICAP_XFERMECH; 
   twCap.ConType = TWON_ONEVALUE;

   L_TwainCreateNumericContainerOneValue(&twCap, TWAINNUMERICTYPE_TW_UINT16, TWSX_NATIVE);

   L_TwainSetCapability(g_hSession, &twCap, LTWAIN_CAPABILITY_SET);
   L_TwainFreeContainer(&twCap);
   L_TwainEndCapsNeg(g_hSession);

   nRet = L_TwainAcquire(g_hSession, pBitmap, sizeof(BITMAPHANDLE), BmpCB, LTWAIN_SHOW_USER_INTERFACE, NULL, NULL); 
   if (nRet == SUCCESS)
      MessageBox(NULL, TEXT("The image acquisition process completed."), TEXT("Notice"), MB_OK);
   else
      MessageBox(NULL, TEXT(" The image acquisition process failed!"), TEXT("Error"), MB_OK);
}