VintaSoft Twain .NET SDK v10.3
In This Topic
    TWAIN device manager
    In This Topic

    TWAIN device manager is the library, which serves as a bridge between a TWAIN driver and user application (VintaSoft Twain .NET SDK).

    The following TWAIN device managers are present at current time:

    1. TWAIN_32.DLL - 32-bit TWAIN device manager compatible with TWAIN 1.x specification.
      This device manager allows to work only with 32-bit TWAIN 1.x and WIA drivers.
      Normally TWAIN_32.DLL is located in "C:\Windows\" directory and included in distributive package of all versions of Windows.

    2. TWAINDSM.DLL and TWAINDSM32.MSM - 32-bit TWAIN device manager compatible with TWAIN 2.x specification.
      This device manager allows to work only with 32-bit TWAIN 1.x and 2.x drivers.
      Files of this device manager are NOT included in distributive package of Windows. On 32-bit systems the TWAIN device manager files must be placed in "C:\Windows\System32\" directory. On 64-bit systems the TWAIN device manager files must be placed in "C:\Windows\SysWow64\" directory.
      Latest version of this device manager can be found here:
      http://www.twain.org or http://sourceforge.net/projects/twain-dsm/files/.

    3. TWAINDSM.DLL and TWAINDSM64.MSM - 64-bit TWAIN device manager compatible with TWAIN 2.x specification.
      This device manager allows to work only with 64-bit TWAIN 2.x drivers.
      Files of this device manager are NOT included in distributive package of Windows. On 64-bit systems the TWAIN device manager files must be placed in "C:\Windows\System32\" directory.
      Latest version of this device manager can be found here:
      http://www.twain.org or http://sourceforge.net/projects/twain-dsm/files/.


    If SDK is used in 32-bit application the SDK can use:
    If SDK is used in 64-bit application the SDK can use:

    For working with TWAIN device manager it is necessary to create an instance of DeviceManager class. Type of TWAIN device manager can be set using the DeviceManager.IsTwain2Compatible property. The DeviceManager.IsTwainAvailable property allows to check if TWAIN device manager is present in the system. The DeviceManager.TwainDllPath property allows to define custom path to TWAIN device manager.

    Here is an example that shows how check if TWAIN device manager is installed in the system:
    ''' <summary>
    ''' Checks that TWAIN device manager is installed in the system.
    ''' </summary>
    Private Sub CheckTwain()
        Dim isTwainAvailable As Boolean = False
    
        ' create the device manager
        Using deviceManager As New DeviceManager()
            ' specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = True
            ' if TWAIN device manager 2.x is available
            If deviceManager.IsTwainAvailable Then
                Console.WriteLine("TWAIN device manager 2.x is available.")
                isTwainAvailable = True
            End If
    
            ' specify that TWAIN device manager 1.x must be used
            deviceManager.IsTwain2Compatible = False
            ' if TWAIN device manager 1.x is available
            If deviceManager.IsTwainAvailable Then
                Console.WriteLine("TWAIN device manager 1.x is available.")
                isTwainAvailable = True
            End If
    
            ' if TWAIN device manager is NOT available
            If Not isTwainAvailable Then
                Console.WriteLine("TWAIN device manager is NOT available.")
            End If
        End Using
    End Sub
                  
    
    /// <summary>
    /// Checks that TWAIN device manager is installed in the system.
    /// </summary>
    void CheckTwain()
    {
        bool isTwainAvailable = false;
    
        // create the device manager
        using (DeviceManager deviceManager = new DeviceManager())
        {
            // specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = true;
            // if TWAIN device manager 2.x is available
            if (deviceManager.IsTwainAvailable)
            {
                Console.WriteLine("TWAIN device manager 2.x is available.");
                isTwainAvailable = true;
            }
    
            // specify that TWAIN device manager 1.x must be used
            deviceManager.IsTwain2Compatible = false;
            // if TWAIN device manager 1.x is available
            if (deviceManager.IsTwainAvailable)
            {
                Console.WriteLine("TWAIN device manager 1.x is available.");
                isTwainAvailable = true;
            }
    
            // if TWAIN device manager is NOT available
            if (!isTwainAvailable)
                Console.WriteLine("TWAIN device manager is NOT available.");
        }
    }
                    
    


    Here is an example that shows how use 32-bit TWAIN and WIA drivers in 32-bit application:
    ''' <summary>
    ''' Shows a list of 32-bit TWAIN and WIA drivers in 32-bit application.
    ''' </summary>
    ''' <remarks>
    ''' This code must be used in 32-bit application.
    ''' </remarks>
    Private Sub Use32BitTwainAndWiaDriversIn32BitApplication()
        ' create the device manager
        Using deviceManager As New DeviceManager()
            ' specify that TWAIN device manager 1.x must be used
            deviceManager.IsTwain2Compatible = False
    
            ' open the device manager
            deviceManager.Open()
    
            ' show a dialog for selecting 32-bit TWAIN or WIA driver
            deviceManager.ShowDefaultDeviceSelectionDialog()
        End Using
    End Sub
                  
    
    /// <summary>
    /// Shows a list of 32-bit TWAIN and WIA drivers in 32-bit application.
    /// </summary>
    /// <remarks>
    /// This code must be used in 32-bit application.
    /// </remarks>
    void Use32BitTwainAndWiaDriversIn32BitApplication()
    {
        // create the device manager
        using (DeviceManager deviceManager = new DeviceManager())
        {
            // specify that TWAIN device manager 1.x must be used
            deviceManager.IsTwain2Compatible = false;
    
            // open the device manager
            deviceManager.Open();
    
            // show a dialog for selecting 32-bit TWAIN or WIA driver
            deviceManager.ShowDefaultDeviceSelectionDialog();
        }
    }
                    
    


    Here is an example that shows how use 32-bit TWAIN drivers in 64-bit application:
    ''' <summary>
    ''' Shows a list of 32-bit TWAIN drivers in 64-bit application.
    ''' </summary>
    ''' <remarks>
    ''' This code must be used in 64-bit application.
    ''' </remarks>
    Private Sub Use32BitTwainDriversIn64BitApplication()
        ' create the device manager
        Using deviceManager As New DeviceManager()
            ' specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = True
            ' specify that 64-bit TWAIN device manager 2.x must use 32-bit devices
            deviceManager.Use32BitDevices()
    
            ' open the device manager
            deviceManager.Open()
    
            ' show a dialog for selecting 32-bit TWAIN driver
            deviceManager.ShowDefaultDeviceSelectionDialog()
        End Using
    End Sub
                  
    
    /// <summary>
    /// Shows a list of 32-bit TWAIN drivers in 64-bit application.
    /// </summary>
    /// <remarks>
    /// This code must be used in 64-bit application.
    /// </remarks>
    void Use32BitTwainDriversIn64BitApplication()
    {
        // create the device manager
        using (DeviceManager deviceManager = new DeviceManager())
        {
            // specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = true;
            // specify that 64-bit TWAIN device manager 2.x must use 32-bit devices
            deviceManager.Use32BitDevices();
    
            // open the device manager
            deviceManager.Open();
    
            // show a dialog for selecting 32-bit TWAIN driver
            deviceManager.ShowDefaultDeviceSelectionDialog();
        }
    }
                    
    


    Here is an example that shows how use 64-bit TWAIN drivers in 64-bit application:
    ''' <summary>
    ''' Shows a list of 64-bit TWAIN drivers in 64-bit application.
    ''' </summary>
    ''' <remarks>
    ''' This code must be used in 64-bit application.
    ''' </remarks>
    Private Sub Use64BitTwainDriversIn64BitApplication()
        ' create the device manager
        Using deviceManager As New DeviceManager()
            ' specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = True
    
            ' open the device manager
            deviceManager.Open()
    
            ' show a dialog for selecting 64-bit TWAIN driver
            deviceManager.ShowDefaultDeviceSelectionDialog()
        End Using
    End Sub
                  
    
    /// <summary>
    /// Shows a list of 64-bit TWAIN drivers in 64-bit application.
    /// </summary>
    /// <remarks>
    /// This code must be used in 64-bit application.
    /// </remarks>
    void Use64BitTwainDriversIn64BitApplication()
    {
        // create the device manager
        using (DeviceManager deviceManager = new DeviceManager())
        {
            // specify that TWAIN device manager 2.x must be used
            deviceManager.IsTwain2Compatible = true;
    
            // open the device manager
            deviceManager.Open();
    
            // show a dialog for selecting 64-bit TWAIN driver
            deviceManager.ShowDefaultDeviceSelectionDialog();
        }
    }