Startup2 Method

Summary

Initializes the TWAIN session.

Syntax
C#
VB
C++
public void Startup2( 
   IntPtr owner, 
   string manufacturer, 
   string productFamily, 
   string version, 
   string application, 
   TwainStartupFlags flags, 
   TwainLanguage language, 
   TwainCountry country 
) 
Public Sub Startup2( _ 
   ByVal owner As IntPtr, _ 
   ByVal manufacturer As String, _ 
   ByVal productFamily As String, _ 
   ByVal version As String, _ 
   ByVal application As String, _ 
   ByVal flags As TwainStartupFlags, _ 
   ByVal language As TwainLanguage, _ 
   ByVal country As TwainCountry _ 
)  
public: 
void Startup2(  
   IntPtr owner, 
   String^ manufacturer, 
   String^ productFamily, 
   String^ version, 
   String^ application, 
   TwainStartupFlags flags, 
   TwainLanguage language, 
   TwainCountry country 
)  

Parameters

owner
The parent's window handle. This can be NULL.

manufacturer
Character string that contains the manufacturer's name (optional).

productFamily
Character string that contains the application's product family (optional).

version
Character string that contains the version information (optional).

application
Character string that contains the application's name (optional).

flags
Flag that determines the method's behavior.

language
Specifies which language to show in the UI.

country
Specifies which country to show in the UI.

Remarks

A TWAIN session is a communication session between Leadtools.Twain and your TWAIN sources. The internal TWAIN session handle that is created provides access to this TWAIN session.

Either the Startup or the Startup2 method must be called before calling any LEADTOOLS TWAIN toolkit functions.

When the TWAIN session is no longer needed, end it by calling the Shutdown method. For every call to the Startup2 method there must be a call to the Shutdown method.

The behavior of the IsAvailable, Startup, and Startup2 functions depends on whether SetVersion has been called.

  • If SetVersion has not been called, the functions search for the 64-bit TWAINdsm driver first. If found, it is loaded and the TWAIN version will be "TWAIN_VERSION2".

  • If that fails or no 64-bit drivers are found, the TWAIN API internally calls the THUNK utility.

    • If not found it will return an error.
  • If found, it will load the THUNK utility and search for the 32-bit TWAINdsm driver.
    • If found, it is loaded and used.
  • If not found, it will use the THUNK utility to attempt to load the 32-bit twain_32 library.
    • If found, it is loaded and used.
  • If not found it will return an error.

The following figure summarizes the default behavior.

default twain behavior

Use the value of flags to specify the function's behavior, as follows:

  • Pass None to the flags parameter to initialize the TWAIN session without the multi-threaded option.

  • Pass InitializeMultithreaded to the flags parameter to initialize the TWAIN session with the multi-threaded option.

  • Pass UseThunkServer to the flags parameter to force the TWAIN session to use the THUNK utility. The LEADTOOLS THUNK utility was developed especially for those cases where 64-bit TWAIN drivers are not suitable/available for the application being developed. When the UseThunkServer flags is passed, the TWAIN API skips searching for 64-bit TWAIN drivers and only looks for the 32-bit TWAIN drivers.  Pass this value only when using a TWAIN device that does not have a 64-bit driver and you are working on a 64-bit operating system.  When using the THUNK server be sure to include in your distributables for your application all dependency files listed in the Using the LEADTOOLS THUNK Utility with TWAIN topic.  This behavior is summarized in the following figure:

    UseThunkServer passed to StartUp2

You can override the default behavior and explicitly set which version of TWAIN the selected device will use. To do so, call SetVersion and pass “Version1” to use version 1.9. The toolkit will only attempt to load the twain_32 DLL. Pass “Version2" to use version 2.x. 

NOTE: Setting the version affects the behavior for the rest of the session. For more information, refer to Setting which TWAIN Specification Version to Use and Managing the TWAIN Source.

Call GetVersion to determine which TWAIN specification is currently being used by the LEADTOOLS TWAIN toolkit.

Note: If this function throws a TwainExceptionCode::InvalidDll exception, it is likely because the TWAINDSM.DLL's version in the system folder is old. Make sure to have at least version 2.0.9.0 of this DLL. You can download it from www.twain.org.

Note: If this function throws a TwainExceptionCode::NotInitialized exception while the UseThunkServer flag is used, then most likely it is because the THUNK server (ltthunkserver.exe) failed to start. In this case, make sure the ltthunkserver.exe is registered correctly and all dependencies listed in the Using LEADTOOLS THUNK Utility with TWAIN topic reside in the same folder where the ltthunkserver.exe is located. For more information, refer to Initializing a TWAIN Source, Freeing the TWAIN Session, and Using LEADTOOLS THUNK Utility with TWAIN.

Note: When using the thunk server, working on a 64-Bit operating system, and using a TWAIN device without a 64-Bit driver, it is preferred to pass IntPtr.Zero to the owner parameter.

TWAIN Session Behavior

A TWAIN session is a communication session between LEADTOOLS Twain and your TWAIN sources. The internal TWAIN session handle provides access to this TWAIN session.

Example
C#
VB
using Leadtools; 
using Leadtools.Twain; 
 
public void Startup2Example(IntPtr parent) 
{ 
   TwainSession session = new TwainSession(); 
 
   try 
   { 
      session.Startup2(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None, TwainLanguage.LanguageEnglish, TwainCountry.CountryUsa); 
   } 
   catch (Exception ex) 
   { 
      MessageBox.Show(ex.Message); 
   } 
 
   session.Shutdown(); 
} 
Imports Leadtools 
Imports Leadtools.Twain 
 
 
Public Sub Startup2Example(ByVal parent As IntPtr) 
   Dim session As TwainSession = New TwainSession() 
 
   Try 
      session.Startup2(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None, TwainLanguage.LanguageEnglish, TwainCountry.CountryUsa) 
   Catch ex As Exception 
      MessageBox.Show(ex.Message) 
   End Try 
 
   session.Shutdown() 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Twain Assembly