[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Can not see Devices in Twain's select source

Posted on 1998-11-04
4
Medium Priority
?
539 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
[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
  • 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 600 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

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.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

650 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