Twain Feeder : Tutorial # 1

Take the following steps to create and run a program that implements LEADTOOLS TWAIN features. Remember, the purpose of the TWAIN tutorial is to provide you a quick and easy way to generate a TWAIN program.

1.

Create a new directory in the LTWINxxx\EXAMPLES\DLL directory called EZTWNFEEDER1.

2.

Copy everything in the EZFUNC directory into the EZTWNFEEDER1 directory.

3.

Rename the EZFunc.c file to be EZFunc.cpp.

4.

Remove the EXFunc.c from the project and add the EZFunc.cpp in its place.

5.

Compile the project as it is and run EZFUNC32.exe to familiarize yourself with the basic program. You can run the exe file from the MS-DOS prompt, or set the image file to load through the Project->Settings->Debug->Program Arguments menu.

6.

On the Insert menu, select Files into Project. Add the Lttwn_n.lib file to the project from the LTWINxxx\LIB directory.

7.

Define the following global variables in EZFUNC.CPP in the EZTWNFEEDER1 directory:

HTWAINSESSION hSession = NULL;

8.

In the project workspace go to the resources tab. Add a menu ("MAIN_MENU") to the application with the following menu items:

 

ID

Caption

 

IDM_ACQUIRE

Acquire

9.

In the InitApplication function change the line:

wcWindowClass.lpszMenuName = NULL;  /* No menu */
to be
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");

10.

In the EZFunc.cpp add the following includes:

#include "resource.h"

11.

In the MainWndProc function and before the handling of the WM_PALETTECHANGED message add the following code:

   case WM_COMMAND: 
      {
         switch (LOWORD(wParam)) 
         {
         case IDM_ACQUIRE: 
            {
            }
            break; 
      }
      break;

12.

In the IDM_ACQUIRE menu handler add the following code:

         case IDM_ACQUIRE:
            {
               TwainTestFeeder1(hWnd);
            }

13.

Add the following function to the EZFUNC.CPP:

L_INT L_FAR L_EXPORT TwainAcquireCB(HTWAINSESSION hTwain, pBITMAPHANDLE pBitmap, L_VOID L_FAR * pUserData)
{
   // ... 
   // set your code here ... 
   // ... 

   return(SUCCESS); 
}

14.

Add the following function to the EZFUNC.CPP:

void TwainTestFeeder1(HWND hWnd) 
{
   HTWAINSESSION hSession; 
   APPLICATIONDATA AppData; 
   TW_CAPABILITY twCap; 
   L_INT nRet; 
   L_BOOL bEnable; 

   memset(&AppData, 0, sizeof(APPLICATIONDATA)); 

   AppData.hWnd = hWnd; 
   lstrcpy (AppData.szManufacturerName, TEXT("LEAD Technologies, Inc.")); 
   lstrcpy (AppData.szAppProductFamily, TEXT("LEAD Sample"));
   lstrcpy (AppData.szVersionInfo,      TEXT("Version 1.0"));
   lstrcpy (AppData.szAppName,          TEXT("LEAD Sample"));
   AppData.uStructSize = sizeof(APPLICATIONDATA); 

   nRet = L_TwainInitSession(&hSession, &AppData); 
   if (nRet != TWAIN_SUCCESS) 
      return; 

   L_TwainSelectSource(hSession, NULL); 
   L_TwainStartCapsNeg(hSession); 

   twCap.Cap = CAP_AUTOFEED; 
   twCap.ConType = TWON_ONEVALUE; 
   twCap.hContainer = GlobalAlloc(GHND, sizeof(TW_ONEVALUE)); 

   pTW_ONEVALUE pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer); 
   bEnable = TRUE; 

   pOneValue->ItemType = TWTY_BOOL; 
   pOneValue->Item = (TW_UINT32)bEnable; 

   GlobalUnlock(twCap.hContainer); 

   nRet = L_TwainSetCapability(hSession, &twCap, LTWAIN_CAPABILITY_SET); 
   if (nRet == TWAIN_SUCCESS) 
      MessageBox(hWnd, TEXT("AutoFeed capability is enabled"), TEXT("Notice"), MB_OK); 
   else
      MessageBox(hWnd, TEXT("Can't enable AutoFeed capability"), TEXT("Notice"), MB_OK); 

   L_TwainEndCapsNeg(hSession); 

   // try to acquire pages using AutoFeed capability
   L_TwainAcquire(hSession, NULL, sizeof(BITMAPHANDLE), TwainAcquireCB, LTWAIN_SHOW_USER_INTERFACE | LTWAIN_MODAL_USER_INTERFACE, NULL, NULL); 

   L_TwainEndSession(&hSession); 
}

15.

Compile and test the program.