DTwainInterface::DTwainInterface

Top  Previous  Next

 

Use either one of these constructors to construct the interface to the DTWAIN API functions. One form of the constructor provides a way using the DTwainAppInfo class to set the TWAIN application information.

 

 

When a DTwainInterface is created, the DTWAIN DLL is automatically initialized.

 

 

 

 

Syntax

 

 

DTwainInterface::DTwainInterface( const DTwainAppInfo& AppInfo );

 

DTwainInterface::DTwainInterface( bool bInitInterface = true );

 

DTwainInterface::DTwainInterface( HWND hWnd, const std::string& TwainDLL="" );

 

DTwainInterface::DTwainInterface( const DTwainAppInfo& AppInfo, HWND hWnd, const std::string& TwainDLL="" );

 

Parameters

AppInfo

 

Reference to a DTwainAppInfo object that contains the initial TWAIN application information when the TWAIN Session is started.

 

hWnd

 

HANDLE to a window that will receive DTWAIN notifications when an acquisition is being executed, or NULL if there is no window associated with notification processing.  A Twain session is started using this value

 

TwainDLL

 

Name of the Twain DLL source manager.  If this is empty, the name that will be used is "TWAIN_32.DLL".  A Twain session is started using this value.

 

 

 

 

 

Comments

 

 

Except for DTwainInterface::DTwainInterface( false ), all of the constructors defined above starts the DTWAIN interface.  The following comments pertain to the DTwainInterface constructors other than DTwainInterface( false ).

 

If you are using the DLL version of DTWAIN (DTWAIN32.DLL or DTWAIN64.DLL), each time a new DTwainInterface is constructed and DTWAIN is initialized, an internal reference count is incremented.  The first DTwainInterface object always attempts to initialize the DTWAIN DLL.  To uninitialize the DTWAIN DLL, the reference count must be 0, or an explicit call to DTwainInterface::ForceTwainShutdown must be called.  The reference count is decremented each time the destructor for DTwainInterface is called.

 

 

Note that if you are using the DYNDTWAIN classes (DTWAIN_USEDYNDTWAIN is defined), and the reference count is 0, LoadLibrary( ) and InitDTWAINInstance are called to load the DTWAIN32.DLL at runtime and to establish the function pointer interface to the exported DLL functions.

 

The best place to create a DTwainInterface object is at application startup.  When the application shuts down, the destructor to DTwainInterface automatically shuts TWAIN down gracefully.  However, remember that an internal reference counter is maintained, so for every DTwainInterface object created, there should be a DTwainInterface destructor called (this should be especially noted if the DTwainInterface is created dynamically using operator new, since operator delete must be called by the application).

 

 

If you declare a DTwainInterface object and use true as the argument (or use no arguments), then the default DTWAIN/TWAIN setup is initialized and used.  The default is that the TWAIN DLL used will be TWAIN_32.DLL, no window handle is associated with DTWAIN notifications, and the Application Information (DTwainAppInfo) is initialized with empty strings as the information.

 

 

 

Declaring DTwainInterface objects without initializing DTWAIN (the DTwainInterface( false ) option):

If you declare a DTwainInterface object and use false as the argument to the constructor,  your application must call DTwainInterface::InitInterface to initialize DTWAIN:

 

Example:

 

    DTwainInterface TI( false );

    TI.InitInterface( );

 

Therefore, if you have a user-defined class or struct, and one of the members of the class/struct is a DTwainInterface object, if you do not want to automatically initialize DTWAIN when an instance of your struct/class is created, you must do something similar to the following:

 

#include "cdtwain.h"

class MyClass

{

    public:

        MyClass( /* possible arguments */ ) : MyInterface( false ) { }

         //....

         // other member functions

 

    private:

        DTWAIN::DTwainInterface MyInterface;

        // other members  

};

 

Note that the class's member-initialization list is used to initialize the DTwainInterface object with a false argument.