[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using EZTwain library

Posted on 1998-11-24
2
Medium Priority
?
469 Views
Last Modified: 2012-05-04
Now I'm using EZTwain library to acquire image from scanner, using C++Builder. The code to acquire image is

  HANDLE hDib;
  hDib = TWAIN_AcquireNative(hwnd, PIXEL_TYPE);

where hwnd is MainForm->Handle  /* my main window handle */
  and PEXEL_TYPE is 0           /* any type */

Is it correct?? if yes, I try to get the bitmap information by
 
  LPBITMAPINFOHEADER lpbi;  
  lpbi = (LPBITMAPINFOHEADER)hDib;

BUT lpbi has incorrect result. What's wrong with it?
0
Comment
Question by:mrbird
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:mrbird
ID: 1178534
Adjusted points to 250
0
 
LVL 7

Accepted Solution

by:
psdavis earned 500 total points
ID: 1178535
Hello again, MrBird...

Here's my version of TransferNativeImage.  I know that this works.  I've always had trouble with EzTwain.  It seemed like it just barely worked only in it's own circumstances.  

I've added the message loop directly inside of the class in the PreTranslateMessage function, and I believe that they require you to put it inside of your application.  That's where I always had my problem, make sure it looks the same (similar) in yours.

BOOL CTwain::PreTranslateMessage( MSG* pMsg )
{
   if( m_eCurrentState < TWAIN_SOURCE_ENABLED )
      return FALSE;

   TW_EVENT      twEvent;

      twEvent.pEvent    = (TW_MEMREF) pMsg;
      twEvent.TWMessage = MSG_NULL;

   TW_UINT16 twRC = (*m_lpDSM_Entry)( &m_AppId, &m_SourceId, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF) &twEvent );

   if( twRC == TWRC_NOTDSEVENT )
      return FALSE;

      switch( twEvent.TWMessage )
   {
// Retrieve the image!

   case MSG_XFERREADY:
      TRACE0( "TWAIN: Pre-Translate XFerReady\n" );
      TransferNativeImage( );     // XferReady( lpmsg );
      break;

// Default callback closes the source

   case MSG_CLOSEDSREQ:
      TRACE0( "TWAIN: Pre-Translate CloseDSReq\n" );
      StopAcquire( );                  // CloseDSReq
      break;

// No message returned

   case MSG_NULL:
      break;
            } // switch

      return TRUE;
   }


BOOL CTwain::TransferNativeImage( )
{
// Do until there are no more pending transfers
// explicitly initialize the our flags

   BOOL  bReturn = FALSE;
   int   iStatus;

   TW_IMAGEINFO    twImageInfo;
   TW_PENDINGXFERS twPendingXfer;

   memset( &twPendingXfer, 0, sizeof( TW_PENDINGXFERS ));
   twPendingXfer.Count = 0;

   TRACE0( "TWAIN: TransferNative\n" );

   do
   {
      TRACE1( "TWAIN: TransferNative IMAGENATIVEXFER begin: %d\n", twPendingXfer.Count );

      TW_UINT16 twRC2;
      TW_UINT16 twRC = (*m_lpDSM_Entry )( &m_AppId, &m_SourceId, DG_IMAGE, DAT_IMAGEINFO, MSG_GET, (TW_MEMREF) &twImageInfo );

      if( twRC != TWRC_SUCCESS )
      {
         continue;
         }

      TW_UINT32 hBitmap = NULL;

      twRC = (*m_lpDSM_Entry )( &m_AppId, &m_SourceId, DG_IMAGE, DAT_IMAGENATIVEXFER, MSG_GET, (TW_MEMREF) &hBitmap );

      switch( twRC )
      {
         case TWRC_XFERDONE:  // Session is in State 7
                     
            TRACE0( "TWAIN: TransferNative XFERDONE\n" );

         // Acknowledge the end of the transfer and transition to state 6/5

            twRC2 = ( *m_lpDSM_Entry)(&m_AppId, &m_SourceId, DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, (TW_MEMREF) &twPendingXfer );
               
         // close the DSM and DS

            if( twPendingXfer.Count == 0 )
            {      
               LPBITMAPINFOHEADER pBitmap = (LPBITMAPINFOHEADER) GlobalLock( (void*) hBitmap );
//             BYTE* pBitmap = (BYTE*) GlobalLock( (void*) hBitmap );

               freeimage( m_vTwainImage );
               iStatus = dibtoimage( (BYTE*) pBitmap, m_vTwainImage );

            // Free the bitmap now.  The dibtoimage function copied it for us!

               GlobalUnlock( (void*) hBitmap );
               GlobalFree  ( (void*) hBitmap );

               TRACE0( "TWAIN: TransferNative CopyImage\n" );

            // Send a message to the main app that we're done!!

               SendMessage( m_hWnd, PM_XFERDONE, 0, 0);

               StopAcquire( );
               }

            PostMessage( m_hWnd, WM_COMMAND, PM_XFERDONE, 0 );
            TRACE0( "TWAIN: TransferNative PM_XFERDONE\n" );
            break;

         // the user canceled or wants to rescan the image
         // something wrong, abort the transfer and delete the image
         // pass a null ptr back to App

         case TWRC_CANCEL:   // Session is in State 7
         case TWRC_FAILURE:  
         default:
               
         // Source (or User) Canceled Transfer transistion to state 6/5

            twRC2 = (*m_lpDSM_Entry)(&m_AppId, &m_SourceId, DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, (TW_MEMREF) &twPendingXfer );
               
        // Close the DSM and DS

            if( twPendingXfer.Count == 0)
               StopAcquire( );

            PostMessage( m_hWnd, WM_COMMAND, PM_XFERDONE, 0 );
            TRACE0( "TWAIN: TransferNative TWRC_FAILURE\n" );

            break;
         }

      } while( twPendingXfer.Count != 0 );

   TRACE0( "TWAIN: TransferNative exiting\n" );

   return bReturn;
   }

Phillip
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question