Get a Fast Twain Scan from a Scanner

Take the following steps to get fast TWAIN scan using the LEADTOOLS Fast TWAIN features:

  1. Start Microsoft Visual Studio.
  2. Select the File->New menu option, click the Project menu.
  3. From Project Types, select Other Languages to expand it, then select Visual C++ to expand it, then select MFC. From the right window select MFC Application.
  4. In the Project Name dialog box, enter TwainTutor2.
  5. In the Location dialog box, use the Examples\ClassLibrary\MSVC directory of your LEAD installation. For example, if you installed LEADTOOLS in C:\LEADTOOLS21\, enter C:\LEADTOOLS21\Examples\ClassLibrary\MSVC, then Click OK. Then click Next.
  6. Choose Dialog based and click Finish.
  7. Click the Solution Explorer tab, and then click the TwainTutor2 project to expand it. Click the Header files, then open TwainTutor2.h.
  8. Add the following line immediately before the class CTwainTutor2App declaration (keep in mind, you may have to change the path to where the header files reside):

    #include "..\..\..\..\include\ClassLib\ltwrappr.h" 

  9. Click the Class View tab.

  10. Click to open the TwainTutor2 classes branch.
  11. Click CTwainTutor2App, and then double click the CTwainTutor2App(void) constructor.
  12. Add the following lines after //TODO: add construction code here:

    LBase::LoadLibraries(LT_ALL_LEADLIB);   
    L_TCHAR * pszLicenseFile = L"Replace this with the path to the LEADTOOLS license file";   
    L_TCHAR * pszDeveloperKey = L"Replace this with your developer key";   
    LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);   

  13. Create a new file called Imports.cpp and place it beside your project files.

    1. In the Project Workspace, click the Solution Explorer tab.
    2. Double-click the TwainTutor2 folder to open it.
    3. Right-click the Source files folder and select Add New item.
    4. Expand the Visual C++ tree, if it is not already expanded.
    5. Select Code from the sub-tree.
    6. Select C++ File (.cpp) from the right window.
    7. In the Name text box, specify Imports.cpp.
    8. Click the Add button.
    9. Double-click the imports.cpp in the Solution Explorer and add the following lines:
      #include "StdAfx.h"   
      #if defined(WIN64)    
            
      #else   
         #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\Win32\\Ltwvc_u.lib")   
      #endif // #if defined(WIN64)  
  14. Click the Solution Explorer tab.

  15. Double-click the TwainTutor2 folder to open it.
  16. Double-click the Header Files folder to open it. Then double click TwainTutor2Dlg.h file to open it.
  17. Add the following class declaration before the CTwainTutor2Dlg class.

    class LMyTwain : public LTwain 
    { 
       LEAD_DECLAREOBJECT(LMyTwain); 
    public: 
       LMyTwain(); 
       virtual ~LMyTwain(); 
       virtual L_INT BitmapCallBack(pBITMAPHANDLE pBitmap); 
    }; 

  18. Click the Solution Explorer tab.

  19. Double-click the TwainTutor2 folder to open it.
  20. Double-click the Source Files folder to open it. Then double click TwainTutor2Dlg.cpp file to open it.
  21. Add the following class:

    LEAD_IMPLEMENTOBJECT(LMyTwain); 
    LMyTwain::LMyTwain() 
    { 
       EnableCallBack(TRUE); 
    } 
    LMyTwain::~LMyTwain() 
    { 
    } 
    L_INT LMyTwain::BitmapCallBack(pBITMAPHANDLE pBitmap) 
    { 
       //Copy the acquired bitmap here 
       return SUCCESS; 
    } 

  22. Click the Class View tab.

  23. Right-click CTwainTutor2Dlg and select Add Add Variable...
  24. For Variable Type enter LMyTwain, and for Variable Declaration put m_MyTwain. Leave Access as Public and click OK.
  25. Click to open the CTwainTutor2Dlg branch. Double-click the OnInitDialog() function and add the following code after line:

//TODO: Add extra initialization here

   APPLICATIONDATA AppData;    
   memset(&AppData, 0, sizeof(APPLICATIONDATA));    
   AppData.hWnd = m_hWnd;    
   AppData.uStructSize = sizeof(AppData);    
   lstrcpy(AppData.szManufacturerName, _T("LEAD Technologies, Inc."));    
   lstrcpy(AppData.szAppProductFamily, _T("LEAD Test Applications"));   
   lstrcpy(AppData.szVersionInfo, _T("Version 1.0"));   
   lstrcpy(AppData.szAppName, _T("TWAIN Test Application"));   
   m_MyTwain.InitSession(&AppData);  

  1. Right-click the CTwainTutor2Dlg branch, and choose Properties.
  2. From the Properties window toolbar, click the Messages icon. Then click the empty area beside the item WM_DESTROY and choose OnDestroy.
  3. Add the following code after the opening bracket {:

       m_MyTwain.EndSession();   
       LBase::UnloadLibraries(LT_ALL_LEADLIB);  

  4. Click the *Class View tab.

  5. Right-click CTwainTutor2Dlg and select Add "Add Variable...".
  6. For Variable Type enter FASTCONFIG, and for Variable Declaration put m_BestConfig. Leave Access as Public and click OK.
  7. Click on the Solution Explorer tab.
  8. Double-click the "TwainTutor2" folder to open it.
  9. Double-click the "Resource Files" folder to open it. Then double click "TwainTutor2.rc" file to open it, then double click "Dialog", and then double-click IDD_TWAINTUTOR2_DIALOG.
  10. Now, drag and drop 3 buttons, and change their properties as follows:

    Control ID Caption
    Button1 IDC_SELECT_SOURCE Select Source
    Button2 IDC_FIND_FAST_CONFIG Find Fast Config
    Button3 IDC_ACQUIRE_FAST_CONFIG Acquire Fast Config
  11. From the View menu, select the Other Windows menu, then select the Resource View menu, then select the Dialog, and select IDD_TWAINTUTOR2_DIALOG.

  12. Double-click the Select Source button, and add the following code:

       m_MyTwain.SelectSource(NULL);  

  13. From the View menu, select the Other Windows menu, then select the Resource View menu, then select the Dialog, and select IDD_TWAINTUTOR2_DIALOG.

  14. Double-click the Find Fast Config button, and add the following code:

       pFASTCONFIG pTestConfigs = NULL;    
       L_INT       nTestConfigsCount = 0;    
       L_INT       nRet;    
       nRet = m_MyTwain.FindFastConfig(TEXT("c:\\temp"),   
                                       LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,    
                                       8, 5, NULL, 0,    
                                       &pTestConfigs,    
                                       &nTestConfigsCount,    
                                       &m_BestConfig,    
                                       sizeof(FASTCONFIG));    
       if (nRet == SUCCESS)    
          AfxMessageBox(TEXT("Find Fast Configuration process completed"));   
       else   
          AfxMessageBox(TEXT("An error occurred during the Finding Fast Configuration process."));  

  15. From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINTUTOR2_DIALOG

  16. Double-click the Acquire Fast Config button, and add the following code:

       L_INT nRet;    
       nRet = m_MyTwain.FastAcquire(TEXT("c:\\temp\\testconfig.tif"),   
                                     LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,    
                                     m_BestConfig.uTransferMode,    
                                     m_BestConfig.nFileFormat,    
                                     m_BestConfig.nBitsPerPixel,    
                                     TRUE,    
                                     m_BestConfig.ulBufferSize,    
                                     TRUE);    
       if (nRet == SUCCESS)    
          AfxMessageBox(TEXT("Image acquisition using the Fast TWAIN Configuration is completed."));    
       else   
          AfxMessageBox(TEXT("An error occurred while acquiring images using the Fast TWAIN Configuration."));  

  17. Compile and test the program.

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS TWAIN C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.