XBase++ Sample Program
The following XBase++ program is all that is required to do the following:
Check if TWAIN is installed.
Initialize the DTWAIN Dynamic Link Library.
Select a Source
Acquire a page using the Native transfer mode
Save page to a BMP file called "test.bmp"
Shut down any open TWAIN Source's and DTWAIN itself
___________________________________________________________
#include "Dll.ch"
// Include the DTWAIN constants
#include "DTWAIN32.CH"
PROCEDURE Main
LOCAL TwainSource, nDLLHandle, TwainOK, status, fileOption
fileOption := DTWAIN_USENATIVE + DTWAIN_USELONGNAME
status := 0
// Load the DTWAIN DLL
nDLLHandle := DLLLoad( "DTWAIN32.DLL" )
// Check if TWAIN is available
TwainOK := DLLCall( nDLLHandle, DLL_STDCALL, "DTWAIN_IsTwainAvailable" )
IF TwainOK == 1
// Initialize DTWAIN
DLLCall ( nDLLHandle, DLL_STDCALL, "DTWAIN_SysInitialize" )
// Select a TWAIN Source
TwainSource := DLLCall( nDLLHandle, DLL_STDCALL,
"DTWAIN_SelectSource" )
IF TwainSource <> 0
// Acquire a file
DLLCall ( nDLLHandle, DLL_STDCALL,
"DTWAIN_AcquireFile", TwainSource, "Test.bmp", DTWAIN_BMP, fileOption,
DTWAIN_PT_DEFAULT, 1, 1, 1, @status )
ENDIF
// Uninitialize DTWAIN
DLLCall( nDLLHandle, DLL_STDCALL, "DTWAIN_SysDestroy" )
ENDIF
// Unload the DLL
DLLUnload( nDLLHandle )
RETURN
___________________________________________________________
In the example above, note that all the calls to DLLCall
requires a DLL_STDCALL calling convention. The "stdcall" calling convention is
the one used by the DTWAIN DLL, and you must specify to XBase++ that the DTWAIN
functions use this convention.
For XBase++, you must include the "DTWAIN32.CH" header file. This header file
defines the DTWAIN constants that will be used.