• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

Can not see Devices in Twain's select source

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
mrbird
Asked:
mrbird
  • 2
  • 2
1 Solution
 
psdavisCommented:
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
 
mrbirdAuthor Commented:
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
 
psdavisCommented:
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
 
mrbirdAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now