Solved

Can not see Devices in Twain's select source

Posted on 1998-11-04
4
531 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 43
Template syntax for variable length arrays 9 78
Error C2678: binary '!=': no operator found... 4 72
Need some help with design 17 46
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 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