Selecting the TWAIN source

 

There are 2 choices to select the TWAIN data source. You can prompt the user to choose the TWAIN source with a dialog box or can set it programmatically without user interaction.

 

If you want to select the source with a dialog box, use the SelectSource function/method of the BiTWAIN DLL/OCX. SelectSource calls the standard source selection dialog from the TWAIN dynamic link library.

 

For selecting TWAIN sources programmatically you can use the EnumDataSources, GetSystemDefaultDS, SetDataSource, GetCurrentDS functions/methods of the BiTWAIN DLL/OCX. You can get the system default and current DS, enumerate the available data sources on the system, and set the DS for scanning.

 

[VC]

 

/* Getting the current ds */

 

#include “BiTwain.h”

 

DWOD dwNeeded;

LPSTR szSource = NULL;

 

int err = GetCurrentDS(NULL, 0, &dwNeeded);

 

if (dwNeeded > 0)

{

szSource = (LPSTR)calloc(dwNeeded, sizeof(char));

 

            if (szSource)

            {

/* 1. parameter: Name of the DS

   2. parameter: Length of buffer

   3. parameter: Required size for DS */

 

err = GetCurrentDS(szSource, dwNeeded,

&dwNeeded);

 

                        if (err == TW_OK)

                        {

                                    // Success

                        }

                        else

                        {

                                    // Error getting current DS

                        }

                        free(szSource);

            }

}

 

/* Set the current DS */

 

char szName[256];

 

strcpy(szName, “Name of the DS”);

 

/* 1. parameter: Name of the DS to set */

 

int err = SetDataSource(szName);

 

[VB]

 

‘ Getting the current ds

 

Dim currentDS As String

 

currentDS = BiTwain.GetCurrentDS

 

If BiTwain.ErrorCode = TW_OK Then

            ‘ Success

Else

            ‘ Error

End IF

 

‘ Set the current DS

 

Dim Err As Long

Dim szName As Srting

 

szName = ‘Name of DS’

 

Err = BiTwain.SetDataSource(szName)

 

If BiTwain.ErrorCode = TW_OK Then

            ‘ Success

Else

            ‘ Error

End IF

 

[C#]

 

/* Getting the current ds */

 

string szSource;

 

szSourece = BiTwain.GetCurrentDS();

 

if (BiTwain.ErrorCode ==

 (int)BITWAINLib.enumErrorCodes.TW_OK)

{

// Success

}

else

{

            // Error

}

 

/* Set the current DS */

 

string szName;

 

szName = “Name of DS”;

 

int err = BiTwain.SetDataSource(szName);

 

if (err == (int)BITWAINLib.enumErrorCodes.TW_OK)

{

            // Success

}

else

{

            // Error

}