Solved

Can not see Devices in Twain's select source

Posted on 1998-11-04
4
521 Views
Last Modified: 2012-06-21
I'm using C++Builder to read the image from scanner by using Twain library.
I tried to show the select device dialog, with the following sequence of tripet command.

== After load library successfully ==

rc = (*pDSM_Entry)(&MyApp, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF)&MyWinHandle );

rc = (*pDSM_Entry)(&MyApp, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, (TW_MEMREF)&NewHandle);

There is a window pop up but there is nothing inside, I use other sample (TWACK) it can see device both 16 and 32 bits versions.
What's wrong with my program.

Thank you
bird

ps. for MyWinHandle what it should be my applicaion's handle or my mainform's handle
0
Comment
Question by:mrbird
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1177013
Here's my code to open up the source list.  Good luck.

BOOL CTwain::OpenSourceList( )
{
   TRACE0( "TWAIN: Select Source Attempted\n" );

   if( m_eCurrentState >= TWAIN_SOURCE_OPEN )
   {
      AfxMessageBox( "A Data Source is already open!" );
      return FALSE;
      }

   TW_IDENTITY NewIdentity;
   
   #if _WIN32
      memset( &NewIdentity, 0, sizeof( NewIdentity ));
   #else
      _fmemset( &NewIdentity, 0, sizeof( NewIdentity ));
   #endif
   
   TW_UINT16 twRC = (*m_lpDSM_Entry )( &m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, (TW_MEMREF) &NewIdentity );
     
// This call performs one important function:
// - should cause SM to put up dialog box of available Source's
// - tells the SM which application, m_AppId.id, is requesting, REQUIRED
// - returns the SM assigned NewDSIdentity.id field, you check if changed
//  (needed to talk to a particular Data Source)
// - be sure to test return code, failure indicates SM did not close !!

   twRC = (*m_lpDSM_Entry )( &m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, (TW_MEMREF) &NewIdentity );

   if( twRC != TWRC_SUCCESS )
   {
      AfxMessageBox( "Select DS Failed with an error!" );
      return FALSE;
      }

   m_SourceId = NewIdentity;

   TRACE0( "TWAIN: Select Source Succeeded\n" );
   
   return TRUE;
   }


Phillip
0
 

Author Comment

by:mrbird
ID: 1177014
Sorry it didn't work, and it go in to the loop:

   if( twRC != TWRC_SUCCESS )
   {
      AfxMessageBox( "Select DS Failed with an error!" );
      return FALSE;
   }
I tested my program, it load twain_32.dll and one xxx.ds (data source file) successfully but the ds didn't show up in the selection box.
I tried to get default data source but it also fail??
I tried to run another app. that use EZtwain it load the same lib. and ds. and it works fine. (My code is the same as EZtwain code)
0
 
LVL 7

Accepted Solution

by:
psdavis earned 200 total points
ID: 1177015
It's not this code.  I'm sure of it.  It's in several different programs all working fine.  It must be somewhere where you are calling it instead.

BOOL CTwain::SelectSource( )
{
   TRACE0( "TWAIN: Select Source\n" );

   if( ! OpenSourceManager( ))
      return FALSE;

   OpenSourceList( );
   CloseSourceManager( );

   return TRUE;
   }

BOOL CTwain::OpenSourceManager( )
{
   TRACE0( "TWAIN: OpenSourceManager Attempted\n" );

   if( m_eCurrentState >= TWAIN_MANAGER_OPEN )
      return TRUE;

   if( ! LoadSourceManager( ))
      return FALSE;

   RegisterApp( 1, 0, TWLG_USA, TWCY_USA, "Visa.exe 1.0 10/10/97", "The Phoenix Group", "Scanning", "Visa" );

// Now initialize it!

   TW_UINT16 iStatus = (*m_lpDSM_Entry )( &m_AppId, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &m_hWnd );

   if( iStatus != TWRC_SUCCESS )
   {
      AfxMessageBox( "Error in Open Source Manager!" );
      return FALSE;
      }

   m_eCurrentState = TWAIN_MANAGER_OPEN;

   TRACE0( "TWAIN: OpenSourceManager Succeeded\n" );

   return TRUE;
   }

void CTwain::RegisterApp(           // record application information
   int   sMajorNum, int sMinorNum,  // major and incremental revision e.g. version 2.1, nMajorNum == 2, nMinorNum == 1
   int   sLanguage,                 // language of this version (use TWLG_xxx from TWAIN.H)
   int   sCountry,                  // country of this version (use TWCY_xxx from TWAIN.H)
   LPSTR lpszVersion,               // version info string e.g. "1.0b3 Beta release"
   LPSTR lpszMfg,                   // name of manufacturer/developer e.g. "Crazbat Software"
   LPSTR lpszFamily,                // product family e.g. "BitStomper"
   LPSTR lpszProduct)               // specific product e.g. "BitStomper Deluxe Pro"
{
   memset( &m_AppId, 0, sizeof( TW_IDENTITY ));

   m_AppId.Id = 0;                       // init to 0, but Source Manager will assign real value
   m_AppId.Version.MajorNum = (TW_INT16) sMajorNum;
   m_AppId.Version.MinorNum = (TW_INT16) sMinorNum;
   m_AppId.Version.Language = (TW_INT16) sLanguage;
   m_AppId.Version.Country  = (TW_INT16) sCountry;
   m_AppId.ProtocolMajor    = TWON_PROTOCOLMAJOR;
   m_AppId.ProtocolMinor    = TWON_PROTOCOLMINOR;
   m_AppId.SupportedGroups  = DG_IMAGE | DG_CONTROL;

   lstrcpy( m_AppId.Version.Info,  lpszVersion  );
   lstrcpy( m_AppId.Manufacturer,  lpszMfg      );
   lstrcpy( m_AppId.ProductFamily, lpszFamily   );
   lstrcpy( m_AppId.ProductName,   lpszProduct  );
   }

BOOL CTwain::CloseSourceManager( )
{
   TRACE0( "TWAIN: CloseSourceManager Attempted\n" );

   if( m_eCurrentState <= TWAIN_MANAGER_LOADED )
      return TRUE;

   CloseSource( );

   int iStatus = (*m_lpDSM_Entry)( &m_AppId, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF) &m_hWnd );

   if( iStatus != TWRC_SUCCESS )
   {
      AfxMessageBox( "Error in Close DSM!" );
      return FALSE;
      }

   m_eCurrentState = TWAIN_MANAGER_LOADED;

   TRACE0( "TWAIN: CloseSourceManager Succeeded\n" );

   return TRUE;
   }


0
 

Author Comment

by:mrbird
ID: 1177016
Thanks for you answer, psdavis.
For twain.h question it still doesn't work, but I can compile it with Borland C++. I think may be it is a compiler incompatible, so I will delete that question, any way thanks for your help
bird
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now