www.pudn.com > MovieCollector3.rar > Twain.bas, change:2006-07-20,size:80351b


Attribute VB_Name = "Twain" 
' XDefs translation of \EZTwain\VC\eztwain.h 
'----------------------------------------------------------------- 
' EZTWAIN.H - Easy interface to TWAIN library 
' CopyRight$ (C) 1999-2006 by Dosadi.  All Right$s Reserved. 
' 
' Sales, support and licensing information at: www.dosadi.com 
' 
'you will need a copy of the "EZTWAIN.DLL" To use this code 
 
 
 
 
 
 
 
Declare Function TWAIN_SelectImageSource Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' This is the routine to call when the user chooses the "Select Source..." 
' menu command from your application's File menu. 
' In the standard implementation of "Select Source...", your application 
' doesn't need to do anything except make this one call. 
' Note: If only one TWAIN device is installed on a system, it is selected 
' automatically, so there is no need for the user to do Select Source. 
' You should not require your users to do Select Source before Acquire. 
' 
' This function posts the Source Manager's Select Source dialog box. 
' It returns after the user either OK's or CANCEL's that dialog. 
' A return of TRUE(1) indicates OK, FALSE(0) indicates one of the following: 
'   a) The user cancelled the dialog 
'   b) The Source Manager found no data sources installed 
'   c) There was a failure before the Select Source dialog could be posted 
' 
' If you want to be meticulous, disable your "Acquire" and "Select Source" 
' menu items or buttons if TWAIN_IsAvailable() returns false - see below. 
' 
' To enumerate the available data sources, see: 
'     TWAIN_GetSourceList and TWAIN_NextSourceName 
 
Declare Function TWAIN_AcquireToClipboard Lib "Eztwain.dll" (ByVal hwndApp As Long, ByVal wPixTypes As Long) As Long 
' Like AcquireNative, but puts the resulting image, if any, into the 
' system clipboard as a CF_DIB item. If this call fails, the clipboard is 
' either empty or retains its previous content. 
' Returns TRUE(1) for success, FALSE(0) for failure. 
' 
' Useful for environments like Visual Basic where it is hard to make direct 
' use of a DIB handle.  In fact, TWAIN_AcquireToClipboard uses 
' TWAIN_AcquireNative for all the hard work. 
 
Declare Function TWAIN_AcquireToFilename Lib "Eztwain.dll" (ByVal hwndApp As Long, ByVal sFile As String) As Long 
' Acquire an image and save it to a file. 
' If pszFile is NULL or an empty string, the user is prompted for 
' the file name using a standard Save File dialog. 
' 
' The minimal use of EZTwain is to call this function with both arguments NULL (0). 
' 
' If the filename passed as a parameter or entered by the user contains a 
' standard extension (.bmp, .jpg/.jpeg, .tif/.tiff, .png, .pdf, .gif, .dcx) 
' then the file is saved in the implied format. 
' Otherwise the file is saved in the current SaveFormat - see TWAIN_SetSaveFormat. 
 
' See also TWAIN_AcquireFile below. 
' 
' Return values: 
'   0  success. 
'  -1  the Acquire failed. 
'  -2  file open error (invalid path or name, or access denied) 
'  -3  invalid DIB, or image incompatible with file format, or... 
'  -4  writing failed, possibly output device is full. 
' -10  user cancelled File Save dialog 
 
Declare Function TWAIN_DoSettingsDialog Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' Run the device's settings dialog, if this is supported, and return 
' when the user closes the dialog.  See return codes below. 
' 
' If a device is open, work with that device.  If no device is currently 
' open, work with the default device.  (See GetDefaultSourceName) 
' This is an *optional* TWAIN feature - To check if a device supports this, 
' open the device and call TWAIN_GetCapBool(CAP_ENABLEDSUIONLY, FALSE) - 
' if that call returns TRUE(1) then this feature is supported. 
' Return values: 
'    1     dialog was displayed and user clicked OK 
'    0     dialog was displayed and user clicked Cancel 
'   -1     dialog not displayed - some error.  Call LastErrorCode, 
'          ReportLastError, or similar function for more details. 
 
Declare Function TWAIN_EnableSourceUiOnly Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' The underlying 'asynchronous' function for TWAIN_DoSettingsDialog. 
' Opens the device's settings dialog, if this is supported. 
' Returns TRUE (1) if successful, FALSE (0) otherwise. 
' NOTE: If successful, this call leaves the dialog open, so your 
' program must run a message pump at least until the user closes it. 
' If you don't understand what that means, don't call this guy. 
 
'--------- Global Options 
 
Declare Function TWAIN_WaitForImage Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' ** Experimental - Use with caution ** 
' 
' Returns TRUE(1) if TWAIN device is ready to deliver an image. 
'   -- TWAIN_State() will be 6 in this case. 
' Returns FALSE(1) if the application should stop acquiring and close the DS. 
' 
' If no device is open, the default device is opened. 
' If the device is interacting with the user, waits for the user 
' to either start a transfer, or close the device dialog. 
' This function is primarily useful for multiple transfers, in loops like: 
'     IF TWAIN_OpenDefaultSource() AND NegotiateSettings() THEN 
'         WHILE TWAIN_WaitForImage(hwnd) 
'             TWAIN_AcquireToFilename(hwnd, filename) 
'             increment(filename) 
'         END WHILE 
'         TWAIN_CloseSource() 
'     END IF 
 
Declare Sub TWAIN_SetHideUI Lib "Eztwain.dll" (ByVal bHide As Long) 
Declare Function TWAIN_GetHideUI Lib "Eztwain.dll" () As Long 
' These functions control the 'hide source user interface' flag. 
' This flag is cleared initially, but if you set it non-zero, then when 
' a device is enabled it will be asked to hide its user interface. 
' Note that this is only a request - some devices will ignore it! 
' This affects AcquireNative, AcquireToClipboard, and EnableSource. 
' If the user interface is hidden, you will probably want to set at least 
' some of the basic acquisition parameters yourself - see 
' SetUnits, SetPixelType, SetBitDepth and SetResolution below. 
' See also: HasControllableUI 
 
Declare Function TWAIN_IsAvailable Lib "Eztwain.dll" () As Long 
' Call this function any time to find out if TWAIN is installed on the 
' system.  It takes a little time on the first call, after that it's fast, 
' just testing a flag.  It returns 1 if the TWAIN Source Manager is 
' installed & can be loaded, 0 otherwise. 
 
'--------- DIB handling utilities --------- 
 
Declare Sub DIB_SetResolution Lib "Eztwain.dll" (ByVal hdib As Long, ByVal xdpi As Double, ByVal ydpi As Double) 
Declare Sub DIB_SetResolutionInt Lib "Eztwain.dll" (ByVal hdib As Long, ByVal xdpi As Long, ByVal ydpi As Long) 
' Sets the horizontal and vertical resolution of the DIB. 
 
Declare Function DIB_XResolution Lib "Eztwain.dll" (ByVal hdib As Long) As Double 
' Horizontal (x) resolution of DIB, in DPI (dots per inch) 
Declare Function DIB_YResolution Lib "Eztwain.dll" (ByVal hdib As Long) As Double 
' Vertical (y) resolution of DIB, in DPI (dots per inch) 
 
Declare Function DIB_Depth Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
' Depth of DIB, in bits i.e. bits per pixel 
 
Declare Function DIB_PixelType Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
' TWAIN PixelType that describes this DIB: TWPT_BW, TWPT_GRAY, TWPT_RGB, 
' TWPT_PALETTE, TWPT_CMYK, TWPT_CMY, etc. 
 
Declare Function DIB_Width Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
' Width of DIB, in pixels (columns) 
Declare Function DIB_Height Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
' Height of DIB, in lines (rows) 
 
 
Declare Function DIB_AutoCrop Lib "Eztwain.dll" (ByVal hOld As Long, ByVal nOptions As Long) As Long 
' Return a copy of the image in hOld, with the surrounding border 
' of uniform color (if there is one) removed. 
' Uses RegionCopy (above). 
' After this call, remember to DIB_Free(hOld) if you don't need it. 
' nOptions is currently unused and must be 0 (zero). 
 
Declare Function DIB_GetCropRect Lib "Eztwain.dll" (ByVal hdib As Long, ByVal nOptions As Long, ByRef x As Long, ByRef y As Long, ByRef w As Long, ByRef h As Long) As Long 
' Return a suggested crop rectangle to remove a dark border from the image. 
' The rectangle is defined by an upper-Left$ point and a width and height, in pixels. 
' (As needed by DIB_RegionCopy above.) 
' nOptions is currently unused and must be 0. 
' DIB_AutoCrop uses this function to decide what to crop. 
' A return of FALSE means no crop rectangle was found - generally this means 
' that the image has content that extends to the edges, or has no definite borders 
' of dark color.  For convenience, when this function returns FALSE it 
' sets x, y, w and h to specify the entire image. 
 
 
 
 
'--- OBSOLETE: The following functions are for backward compatibility only: 
Declare Function TWAIN_WriteNativeToFilename Lib "Eztwain.dll" (ByVal hdib As Long, ByVal sFile As String) As Long 
Declare Function TWAIN_LoadNativeFromFilename Lib "Eztwain.dll" (ByVal sFile As String) As Long 
'HDIB EZTAPI TWAIN_LoadNativeFromFile(HFILE fh); 
' removed - contact Dosadi if this causes problems for you. 
Declare Function TWAIN_NegotiateXferCount Lib "Eztwain.dll" (ByVal nXfers As Long) As Long 
Declare Function TWAIN_DibDepth Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Function TWAIN_DibWidth Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Function TWAIN_DibHeight Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Function TWAIN_DibNumColors Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Function TWAIN_DibRowBytes Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Sub TWAIN_DibReadRow Lib "Eztwain.dll" (ByVal hdib As Long, ByVal nRow As Long, ByRef prow As Any) 
Declare Function TWAIN_CreateDibPalette Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
Declare Sub TWAIN_DrawDibToDC Lib "Eztwain.dll" (ByVal hDC As Long, ByVal dx As Long, ByVal dy As Long, ByVal w As Long, ByVal h As Long, ByVal hdib As Long, ByVal sx As Long, ByVal sy As Long) 
 
'--------- File Read/Write 
 
'---- File Formats 
Global Const TWFF_TIFF = 0 
Global Const TWFF_BMP = 2 
Global Const TWFF_JFIF = 4 
Global Const TWFF_PNG = 7 
Global Const TWFF_DCX = 97 
Global Const TWFF_GIF = 98 
Global Const TWFF_PDF = 99 
' PDF & GIF support is only provided by EZTwain. 
' Note: BMP support is built into EZTwain, so is always available. 
 
Declare Function TWAIN_IsJpegAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if JPEG/JFIF image files can be read and written. 
' Returns 0 if JPEG support has not been installed. 
 
Declare Function TWAIN_IsPngAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if PNG format support is available. 
 
Declare Function TWAIN_IsTiffAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if TIFF format support is available. 
 
Declare Function TWAIN_IsPdfAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if PDF format support is available. 
 
Declare Function TWAIN_IsGifAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if GIF format support is available. 
 
Declare Function TWAIN_IsDcxAvailable Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if DCX format support is available. 
' Note that DCX files can only hold 1-bit 
' B&W images - EZTwain converts the image data as needed. 
 
Declare Function TWAIN_IsFormatAvailable Lib "Eztwain.dll" (ByVal nFF As Long) As Long 
' Return TRUE (1) if the specified file format support 
' is available for writing and possibly reading files. 
' A format is considered available if EZTwain can load 
' the necessary DLLs.  See the 
 
Declare Function TWAIN_IsFileExtensionAvailable Lib "Eztwain.dll" (ByVal sExt As String) As Long 
' Return TRUE (1) if the file format corresponding to the given 
' file extension ("TIF", ".gif", "jpeg", etc.) is available. 
' Case does not matter, leading '.' is optional. 
 
Declare Function TWAIN_FormatFromExtension Lib "Eztwain.dll" (ByVal sExt As String, ByVal nFF As Long) As Long 
' Return the file-format code (see File Formats above) for 
' the given extension.  If pzExt is unrecognized, returns nFF. 
' Case does not matter, leading '.' is optional. 
 
Declare Function TWAIN_SetSaveFormat Lib "Eztwain.dll" (ByVal nFF As Long) As Long 
' Select the default file format for DIB_WriteToFilename 
' and TWAIN_WriteToFilename to use, when they do not 
' recognize the file extension. 
' Displays a warning message if the format is not available. 
' Returns TRUE (1) if ok, FALSE (0) if format is invalid or not available. 
' See list of file formats above.  Some formats are not supported 
' by some versions of EZTWAIN, or require external DLLs be installed. 
 
Declare Function TWAIN_GetSaveFormat Lib "Eztwain.dll" () As Long 
' Return the currently selected save format. 
 
Declare Sub TWAIN_SetJpegQuality Lib "Eztwain.dll" (ByVal nQ As Long) 
Declare Function TWAIN_GetJpegQuality Lib "Eztwain.dll" () As Long 
' Set the 'quality' of subsequently saved JPEG/JFIF image files. 
' nQ = 100 is maximum quality & minimum compression. 
' nQ = 75 is 'good' quality, the default. 
' nQ = 1 is minimum quality & maximum compression. 
 
Declare Sub TWAIN_SetTiffStripSize Lib "Eztwain.dll" (ByVal nBytes As Long) 
Declare Function TWAIN_GetTiffStripSize Lib "Eztwain.dll" () As Long 
' Set/Get the size of the 'strips' that TIFF files are divided into. 
' Some (bogus) TIFF readers cannot handle multiple strips, to make 
' them happy set the strip size to -1. 
 
Declare Function TWAIN_SetTiffImageDescription Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetTiffDocumentName Lib "Eztwain.dll" (ByVal sText As String) As Long 
' Set the TIFF ImageDescription or DocumentName tags for output. 
' These values apply only to the next TIFF file written, and are cleared 
' once the file is closed. 
 
Declare Function TWAIN_SetTiffCompression Lib "Eztwain.dll" (ByVal nPT As Long, ByVal nComp As Long) As Long 
Declare Function TWAIN_GetTiffCompression Lib "Eztwain.dll" (ByVal nPT As Long) As Long 
' Set/Get the compression mode to use when writing TIFF files. 
' Set returns TRUE (1) if successful, FALSE (0) otherwise. 
' nPT specifies the Pixel Type - See the TWPT_* constants. 
' Different compressions apply to different pixel types - see below. 
' nComp specifies the compression, here are the codes: 
Global Const TIFF_COMP_NONE = 1 
Global Const TIFF_COMP_CCITTRLE = 2 
Global Const TIFF_COMP_CCITTFAX3 = 3 
Global Const TIFF_COMP_CCITTFAX4 = 4 
Global Const TIFF_COMP_LZW = 5 
Global Const TIFF_COMP_JPEG = 7 
Global Const TIFF_COMP_PACKBITS = 32773 
 
' Default for BW is TIFF_COMP_CCITTFAX4 
' Default for all other pixel types is TIFF_COMP_NONE. 
 
Declare Function TWAIN_SetTiffTagLong Lib "Eztwain.dll" (ByVal nTagId As Long, ByVal nValue As Long) As Long 
Declare Function TWAIN_SetTiffTagString Lib "Eztwain.dll" (ByVal nTagId As Long, ByVal sText As String) As Long 
Declare Function TWAIN_SetTiffTagDouble Lib "Eztwain.dll" (ByVal nTagId As Long, ByVal dValue As Double) As Long 
Declare Sub TWAIN_ResetTiffTags Lib "Eztwain.dll" () 
' The functions above allow specific TIFF tags to be set. 
' Whatever value(s) you set will be used in *each image written to TIFF* 
' until you call TWAIN_ResetTiffTags. 
' Note that integer values are appropriately converted to 16- or 32-bit 
' signed or unsigned as needed by the specific tag. 
 
Declare Sub TWAIN_SetFileAppendFlag Lib "Eztwain.dll" (ByVal bAppend As Long) 
Declare Function TWAIN_GetFileAppendFlag Lib "Eztwain.dll" () As Long 
' Set or get the File Append Flag - When this flag is non-zero, any existing 
' TIFF file will be added to, instead of replaced, when written.  When this 
' flag is 0, writing to a TIFF file replaces any existing content. 
' 0 is the default state for this flag. 
' Note: Only TIFF format is affected. 
' This applies to all functions that write images, primarily: 
'  TWAIN_AcquireToFilename, TWAIN_AcquireMultipageFile, 
'  DIB_WriteToFilename, TWAIN_BeginMultipageFile, etc. 
 
'- PDF Metadata ------------------------------------------ 
 
' These functions add information to the next output PDF file: 
Declare Function TWAIN_SetPdfTitle Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetPdfAuthor Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetPdfSubject Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetPdfKeywords Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetPdfCreator Lib "Eztwain.dll" (ByVal sText As String) As Long 
Declare Function TWAIN_SetPdfProducer Lib "Eztwain.dll" (ByVal sText As String) As Long 
 
Declare Function TWAIN_WriteToFilename Lib "Eztwain.dll" (ByVal hdib As Long, ByVal sFile As String) As Long 
' Writes the specified image to a file. 
' These are aliases for DIB_WriteToFilename - please refer to that function. 
 
Declare Function TWAIN_LoadFromFilename Lib "Eztwain.dll" (ByVal sFile As String) As Long 
' Load a .BMP file, or any other available format. 
' Accepts a filename (including path & extension). 
' If pszFile is NULL or points to a null string, the user is 
' prompted to choose a file with a standard File Open dialog. 
' Returns a DIB handle if successful, otherwise NULL. 
 
Declare Function TWAIN_FormatOfFile Lib "Eztwain.dll" (ByVal sFile As String) As Long 
' Return the format of the specified file. 
' See the TWFF_* codes elsewhere in this file. 
' A return value < 0 means 'unrecognized format'. 
 
Declare Function TWAIN_PagesInFile Lib "Eztwain.dll" (ByVal sFile As String) As Long 
' Return the number of pages in the specified file. 
' The format of the file is determined - for multipage formats 
' (TIFF, PDF, DCX), the pages are counted. 
' All other recognized formats return a page count of 1. 
' If the file cannot be opened, read, recognized, etc. 
' this function records an error and returns -1. 
 
Declare Function TWAIN_ViewFile Lib "Eztwain.dll" (ByVal sFile As String) As Long 
' Display the specified file in a viewer window that allows the 
' user to browse to all pages (if more than one). 
' If the file name is NULL or the null string, the user is prompted 
' with a standard file-open dialog, offering all the filetypes that 
' EZTwain thinks it can open. 
' The default dialog has an OK button only. 
' Return values: 
'  1   [OK] button pressed 
'  0   [Cancel] button pressed 
' -1   user cancelled file-open prompt (if you supplied a null filename) 
' -2   error displaying dialog, opening file, etc. 
 
'--------- Multipage File Output 
 
Global Const MULTIPAGE_TIFF = 0 
Global Const MULTIPAGE_PDF = 1 
Global Const MULTIPAGE_DCX = 2 
 
Declare Function TWAIN_SetMultipageFormat Lib "Eztwain.dll" (ByVal nFF As Long) As Long 
Declare Function TWAIN_GetMultipageFormat Lib "Eztwain.dll" () As Long 
' Select/query the default multipage file save format. 
' The default when EZTwain is loaded is MULTIPAGE_TIFF, 
' 
' SetMultipageFormat returns: 
'  0 = success, 
' -1 = invalid/unrecognized format 
' -3 = format is currently unavailable (missing/bad DLL) 
' -7 = Multipage support is not installed. 
 
Declare Function TWAIN_BeginMultipageFile Lib "Eztwain.dll" (ByVal sFile As String) As Long 
' Create an empty multipage file of the given name. 
' IF pszFile includes an extension (.tif, .tiff, .mpt, .pdf or .dcx) 
' then the corresponding format is used for the file. 
' If you do not supply an extension, the default multipage format is used. 
' If pszFile is NULL or points to the null string, the user 
' is prompted with a standard File Save dialog. 
 
' Return values: 
'    0  success 
'   -1  user cancelled File Save dialog 
'   -2  file open error (invalid path or name, or access denied) 
'  -3  file format not available 
'  -5  other unspecified internal error 
'  -7  Multipage support is not installed. 
 
Declare Function TWAIN_DibWritePage Lib "Eztwain.dll" (ByVal hdib As Long) As Long 
'   0   success 
'  -2  internal limit exceeded or insufficient memory 
'  -3  File format is not available (EZxxx DLL not found) 
'  -4  Write error: Output device is full? 
'  -5  invalid/unrecognized file format or 'other' - internal 
'  -5  multipage file not open 
'  -7  Multipage support is not installed. 
 
Declare Function TWAIN_EndMultipageFile Lib "Eztwain.dll" () As Long 
'   0   success 
'  -3  File format is not available 
'  -4  Write error - drive offline, or ?? (very unlikely) 
'  -5  invalid/unrecognized file format or other internal error 
'  -7  Multipage support is not installed. 
 
Declare Function TWAIN_MultipageCount Lib "Eztwain.dll" () As Long 
' Return the number of images (scans) written to the most recently 
' started multipage file.  In other words, this returns a counter 
' which is reset by BeginMultipageFile, and is incremented by DibWritePage. 
 
 
'--------- Application Registration and Licensing 
 
Declare Sub TWAIN_RegisterApp Lib "Eztwain.dll" (ByVal nMajorNum As Long, ByVal nMinorNum As Long, ByVal nLanguage As Long, ByVal nCountry As Long, ByVal sVersion As String, ByVal sMfg As String, ByVal sFamily As String, ByVal sAppTitle As String) 
' 
' TWAIN_RegisterApp can be called *AS THE FIRST CALL*, to register the 
' application. If this function is not called, the application is given a 
' 'generic' registration by EZTWAIN. 
' Registration only provides this information to the Source Manager and any 
' sources you may open - it is used for debugging, and (frankly) by some 
' sources to give special treatment to certain applications. 
 
Declare Sub TWAIN_SetAppTitle Lib "Eztwain.dll" (ByVal sAppTitle As String) 
' The short form of Application/Product name registration. 
' Sets the product name as far as EZTwain and TWAIN are concerned. 
' This title is used in several ways: 
' As the title (caption) of any EZTwain dialog boxes / error boxes. 
' In the progress box of some devices as they transfer images. 
' In the 'software' field of saved image files in some formats, 
' including TIFF. 
 
Declare Sub TWAIN_SetApplicationKey Lib "Eztwain.dll" (ByVal nKey As Long) 
' Unlock EZTwain Pro for use with the current application - call this AFTER 
' calling RegisterApp or SetAppTitle above:  The nKey value must match 
' the application title (product name) passed to one of those functions. 
 
Declare Sub TWAIN_ApplicationLicense Lib "Eztwain.dll" (ByVal sAppTitle As String, ByVal nAppKey As Long) 
' Unlock EZTwain using a Single Application License. 
 
Declare Sub TWAIN_SetVendorKey Lib "Eztwain.dll" (ByVal sVendorName As String, ByVal nKey As Long) 
' Unlock EZTwain using a Universal Application / Vendor License 
 
Declare Sub TWAIN_OrganizationLicense Lib "Eztwain.dll" (ByVal sOrganization As String, ByVal nKey As Long) 
' Unlock EZTwain using an Organization / In-House Application License. 
 
'--------- Error Analysis and Reporting ------------------------------------ 
 
Declare Function TWAIN_GetResultCode Lib "Eztwain.dll" () As Long 
' Return the result code (TWRC_xxx) from the last triplet sent to TWAIN 
 
Declare Function TWAIN_GetConditionCode Lib "Eztwain.dll" () As Long 
' Return the condition code from the last triplet sent to TWAIN. 
' (To be precise, from the last call to TWAIN_DS below) 
' If a source is NOT open, return the condition code of the source manager. 
 
Declare Function TWAIN_UserClosedSource Lib "Eztwain.dll" () As Long 
' Return TRUE (1) if during the last acquire the user asked 
' the DataSource to close.  0 otherwise of course. 
' This flag is cleared each time you start any kind of acquire, 
' and it is set if EZTWAIN receives a 
' MSG_CLOSEDSREQ message through TWAIN. 
 
Declare Sub TWAIN_ErrorBox Lib "Eztwain.dll" (ByVal sMsg As String) 
' Post an error message dialog with an OK button. 
' pszMsg points to a null-terminated message string. 
' The box caption is the current AppTitle - see SetAppTitle. 
' If messages are suppressed (see below) this function does nothing. 
 
Declare Function TWAIN_SuppressErrorMessages Lib "Eztwain.dll" (ByVal bYes As Long) As Long 
' Enable or disable EZTWAIN error messages to the user. 
' When bYes = FALSE(0), error messages are displayed. 
' When bYes = TRUE(non-0), error messages are suppressed. 
' By default, error messages are displayed. 
' Returns the previous state of the flag. 
' 
' EZTWAIN cannot suppress messages from TWAIN or TWAIN device drivers. 
 
Declare Sub TWAIN_ReportLastError Lib "Eztwain.dll" (ByVal sMsg As String) 
' Like TWAIN_ErrorBox, but if some details are available from 
' TWAIN about the last failure, they are included in the message box. 
 
Declare Sub TWAIN_GetLastErrorText Lib "Eztwain.dll" (ByVal sMsg As String) 
' Get a string that describes the last error detected by EZTwain. 
' Note: This function is called by TWAIN_ReportLastError. 
' Note: The returned string may contain end-of-line characters. 
' The parameter is a string variable (char array in C/C++). 
' You are responsible for allocating room for 512 8-bit characters 
' in the string variable before calling this function. 
 
' Return a string that describes the last error detected by EZTwain - 
' see Notes for TWAIN_GetLastErrorText. 
 
Declare Function TWAIN_LastErrorCode Lib "Eztwain.dll" () As Long 
' Return the last internal EZTWAIN error code. (see EZTEC_ codes below) 
 
Declare Sub TWAIN_ClearError Lib "Eztwain.dll" () 
' Set the EZTWAIN internal error code to EZTEC_NONE 
 
'////////////////////////////////////////////////////// 
' EZTwain Error codes 
Global Const EZTEC_NONE = 0 
Global Const EZTEC_START_TRIPLET_ERRS = 1 
Global Const EZTEC_CAP_GET = 2 
Global Const EZTEC_CAP_SET = 3 
Global Const EZTEC_DSM_FAILURE = 4 
Global Const EZTEC_DS_FAILURE = 5 
Global Const EZTEC_XFER_FAILURE = 6 
Global Const EZTEC_END_TRIPLET_ERRS = 7 
Global Const EZTEC_OPEN_DSM = 8 
Global Const EZTEC_OPEN_DEFAULT_DS = 9 
Global Const EZTEC_NOT_STATE_4 = 10 
Global Const EZTEC_NULL_HCON = 11 
Global Const EZTEC_BAD_HCON = 12 
Global Const EZTEC_BAD_CONTYPE = 13 
Global Const EZTEC_BAD_ITEMTYPE = 14 
Global Const EZTEC_CAP_GET_EMPTY = 15 
Global Const EZTEC_CAP_SET_EMPTY = 16 
Global Const EZTEC_INVALID_HWND = 17 
Global Const EZTEC_PROXY_WINDOW = 18 
Global Const EZTEC_USER_CANCEL = 19 
Global Const EZTEC_RESOLUTION = 20 
Global Const EZTEC_LICENSE = 21 
Global Const EZTEC_JPEG_DLL = 22 
Global Const EZTEC_SOURCE_EXCEPTION = 23 
Global Const EZTEC_LOAD_DSM = 24 
Global Const EZTEC_NO_SUCH_DS = 25 
Global Const EZTEC_OPEN_DS = 26 
Global Const EZTEC_ENABLE_FAILED = 27 
Global Const EZTEC_BAD_MEMXFER = 28 
Global Const EZTEC_JPEG_GRAY_OR_RGB = 29 
Global Const EZTEC_JPEG_BAD_Q = 30 
Global Const EZTEC_BAD_DIB = 31 
Global Const EZTEC_BAD_FILENAME = 32 
Global Const EZTEC_FILE_NOT_FOUND = 33 
Global Const EZTEC_FILE_ACCESS = 34 
Global Const EZTEC_MEMORY = 35 
Global Const EZTEC_JPEG_ERR = 36 
Global Const EZTEC_JPEG_ERR_REPORTED = 37 
Global Const EZTEC_0_PAGES = 38 
Global Const EZTEC_UNK_WRITE_FF = 39 
Global Const EZTEC_NO_TIFF = 40 
Global Const EZTEC_TIFF_WRITE_ERR = 41 
Global Const EZTEC_PDF_WRITE_ERR = 42 
Global Const EZTEC_NO_PDF = 43 
Global Const EZTEC_GIFCON = 44 
Global Const EZTEC_FILE_READ_ERR = 45 
Global Const EZTEC_BAD_REGION = 46 
Global Const EZTEC_FILE_WRITE = 47 
Global Const EZTEC_NO_DS_OPEN = 48 
Global Const EZTEC_DCXCON = 49 
Global Const EZTEC_NO_BARCODE = 50 
Global Const EZTEC_UNK_READ_FF = 51 
Global Const EZTEC_DIB_FORMAT = 52 
Global Const EZTEC_PRINT_ERR = 53 
Global Const EZTEC_NO_DCX = 54 
Global Const EZTEC_APP_BAD_CON = 55 
Global Const EZTEC_LIC_KEY = 56 
 
 
 
 
'--------- TWAIN State Control ------------------------------------ 
 
Declare Function TWAIN_LoadSourceManager Lib "Eztwain.dll" () As Long 
' Finds and loads the Data Source Manager, TWAIN.DLL. 
' If Source Manager is already loaded, does nothing and returns TRUE(1). 
' This can fail if TWAIN.DLL is not installed (in the Right$ place), or 
' if the library cannot load for some reason (insufficient memory?) or 
' if TWAIN.DLL has been corrupted. 
 
Declare Function TWAIN_OpenSourceManager Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' Opens the Data Source Manager, if not already open. 
' If the Source Manager is already open, does nothing and returns TRUE. 
' This call will fail if the Source Manager is not loaded. 
 
Declare Function TWAIN_OpenDefaultSource Lib "Eztwain.dll" () As Long 
' This opens the source selected in the Select Source dialog. 
' If some source is already open, does nothing and returns TRUE. 
' Will load and open the Source Manager if needed. 
' If this call returns TRUE, TWAIN is in STATE 4 (TWAIN_SOURCE_OPEN) 
 
' These two functions allow you to enumerate the available data sources: 
Declare Function TWAIN_GetSourceList Lib "Eztwain.dll" () As Long 
' Fetches the list of sources into memory, so they can be returned 
' one by one by TWAIN_GetNextSourceName, below. 
' Returns TRUE (1) if successful, FALSE (0) otherwise. 
 
Declare Function TWAIN_GetNextSourceName Lib "Eztwain.dll" (ByVal sName As String) As Long 
' Copies the next source name in the list into its parameter. 
' The parameter is a string variable (char array in C/C++). 
' You are responsible for allocating room for 33 8-bit characters 
' in the string variable before calling this function. 
' Returns TRUE (1) if successful, FALSE (0) if there are no more. 
 
' Returns the next source name in the list. 
' Returns the empty string when it comes to the end of the list. 
 
Declare Function TWAIN_GetDefaultSourceName Lib "Eztwain.dll" (ByVal sName As String) As Long 
' Copies the name of the TWAIN default source into its parameter. 
' The parameter is a string variable (char array in C/C++). 
' You are responsible for allocating room for 33 8-bit characters 
' in the string variable before calling this function. 
' Normally returns TRUE (1) but will return FALSE (0) if: 
'   - the TWAIN Source Manager cannot be loaded & initialized or 
'   - there is no current default source (e.g. no sources are installed) 
 
' Returns the name of the TWAIN default source device. 
 
Declare Function TWAIN_OpenSource Lib "Eztwain.dll" (ByVal sName As String) As Long 
' Opens the source with the given name. 
' If that source is already open, does nothing and returns TRUE. 
' If another source is open, closes it and attempts to open the specified source. 
' Will load and open the Source Manager if needed. 
 
Declare Function TWAIN_EnableSource Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' Enables the open Data Source. This posts the source's user interface 
' and allows image acquisition to begin.  If the source is already enabled, 
' this call does nothing and returns TRUE. 
 
Declare Function TWAIN_DisableSource Lib "Eztwain.dll" () As Long 
' Disables the open Data Source, if any. 
' This closes the source's user interface. 
' If successful or the source is already disabled, returns TRUE(1). 
 
Declare Function TWAIN_CloseSource Lib "Eztwain.dll" () As Long 
' Closes the open Data Source, if any. 
' If the source is enabled, disables it first. 
' If successful or source is already closed, returns TRUE(1). 
 
Declare Function TWAIN_CloseSourceManager Lib "Eztwain.dll" (ByVal hwnd As Long) As Long 
' Closes the Data Source Manager, if it is open. 
' If a source is open, disables and closes it as needed. 
' If successful (or if source manager is already closed) returns TRUE(1). 
 
Declare Function TWAIN_UnloadSourceManager Lib "Eztwain.dll" () As Long 
' Unloads the Data Source Manager i.e. TWAIN.DLL - releasing 
' any associated memory or resources. 
' If necessary, it will abort transfers, close the open source 
' if any, and close the Source Manager. 
' If successful, it returns TRUE(1) 
 
 
Declare Function TWAIN_IsTransferReady Lib "Eztwain.dll" () As Long 
 
Declare Function TWAIN_EndXfer Lib "Eztwain.dll" () As Long 
 
Declare Function TWAIN_AbortAllPendingXfers Lib "Eztwain.dll" () As Long 
 
'--------- High-level Capability Negotiation Functions -------- 
 
' These functions should only be called in State 4 (TWAIN_SOURCE_OPEN) 
 
Declare Function TWAIN_SetXferCount Lib "Eztwain.dll" (ByVal nXfers As Long) As Long 
' Negotiate with open Source the number of images application will accept. 
' nXfers = -1 means any number 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_NegotiatePixelTypes Lib "Eztwain.dll" (ByVal wPixTypes As Long) As Long 
' Negotiate with the source to restrict pixel types that can be acquired. 
' This tries to restrict the source to a *set* of pixel types. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
' See TWAIN_AcquireNative for some mask constants. 
' A parameter of 0 (TWAIN_ANYTYPE) causes no negotiation & no restriction. 
' You should not assume that the source will honor your restrictions, even 
' if this call succeeds! 
 
'----- Unit of Measure 
' TWAIN unit codes (from twain.h) 
Global Const TWUN_INCHES = 0 
Global Const TWUN_CENTIMETERS = 1 
Global Const TWUN_PICAS = 2 
Global Const TWUN_POINTS = 3 
Global Const TWUN_TWIPS = 4 
Global Const TWUN_PIXELS = 5 
 
Declare Function TWAIN_GetCurrentUnits Lib "Eztwain.dll" () As Long 
' Return the current unit of measure: inches, cm, pixels, etc. 
' Many TWAIN parameters such as resolution are set and returned 
' in the current unit of measure. 
' There is no error return - in case of error it returns 0 (TWUN_INCHES) 
 
Declare Function TWAIN_SetUnits Lib "Eztwain.dll" (ByVal nUnits As Long) As Long 
Declare Function TWAIN_SetCurrentUnits Lib "Eztwain.dll" (ByVal nUnits As Long) As Long 
' Set the current unit of measure for the source. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
' Common unit codes (TWUN_*) are given above. 
' Notes: 
' 1. Most sources do not support all units, some support *only* inches! 
' 2. If you want to get or set resolution in DPI (dots per *inch*), make 
' sure the current units are inches, or you might get Dots-Per-cm! 
' 3. Ditto (same comment) for ImageLayout, see below. 
 
Declare Function TWAIN_GetBitDepth Lib "Eztwain.dll" () As Long 
' Get the current bitdepth, which can depend on the current PixelType. 
' Bit depth is per color channel e.g. 24-bit RGB has bit depth 8. 
' If anything goes wrong, this function returns 0. 
 
Declare Function TWAIN_SetBitDepth Lib "Eztwain.dll" (ByVal nBits As Long) As Long 
' (Try to) set the current bitdepth (for the current pixel type). 
' Note: You should set a PixelType, then set the bitdepth for that type. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
'------- TWAIN Pixel Types (from twain.h) 
Global Const TWPT_BW = 0 
Global Const TWPT_GRAY = 1 
Global Const TWPT_RGB = 2 
Global Const TWPT_PALETTE = 3 
Global Const TWPT_CMY = 4 
Global Const TWPT_CMYK = 5 
 
Declare Function TWAIN_GetPixelType Lib "Eztwain.dll" () As Long 
' Ask the source for the current pixel type. 
' If anything goes wrong (it shouldn't), this function returns 0 (TWPT_BW). 
 
Declare Function TWAIN_SetPixelType Lib "Eztwain.dll" (ByVal nPixType As Long) As Long 
Declare Function TWAIN_SetCurrentPixelType Lib "Eztwain.dll" (ByVal nPixType As Long) As Long 
' Try to set the current pixel type for acquisition. 
' The source may select this pixel type, but don't assume it will. 
 
Declare Function TWAIN_GetCurrentResolution Lib "Eztwain.dll" () As Double 
' Ask the source for the current (horizontal) resolution. 
' Resolution is in dots per current unit! (See TWAIN_GetCurrentUnits above) 
' If anything goes wrong (it shouldn't) this function returns 0.0 
 
Declare Function TWAIN_GetXResolution Lib "Eztwain.dll" () As Double 
Declare Function TWAIN_GetYResolution Lib "Eztwain.dll" () As Double 
' Returns the current horizontal or vertical resolution, in dots per *current unit*. 
' In the event of failure, returns 0.0. 
 
Declare Function TWAIN_SetResolution Lib "Eztwain.dll" (ByVal dRes As Double) As Long 
Declare Function TWAIN_SetResolutionInt Lib "Eztwain.dll" (ByVal nRes As Long) As Long 
Declare Function TWAIN_SetCurrentResolution Lib "Eztwain.dll" (ByVal dRes As Double) As Long 
' Try to set the current resolution (in both x & y). 
' Resolution is in dots per current unit! (See TWAIN_GetCurrentUnits above) 
' Note: The source may select this resolution, but don't assume it will. 
 
' You can also set the resolution in X and Y separately, if your TWAIN 
' device can handle this: 
Declare Function TWAIN_SetXResolution Lib "Eztwain.dll" (ByVal dxRes As Double) As Long 
Declare Function TWAIN_SetYResolution Lib "Eztwain.dll" (ByVal dyRes As Double) As Long 
 
Declare Function TWAIN_SetContrast Lib "Eztwain.dll" (ByVal dCon As Double) As Long 
' Try to set the current contrast for acquisition. 
' The TWAIN standard *says* that the range for this cap is -1000 ... +1000 
 
Declare Function TWAIN_SetBRightness Lib "Eztwain.dll" (ByVal dBri As Double) As Long 
' Try to set the current bRight$ness for acquisition. 
' The TWAIN standard *says* that the range for this cap is -1000 ... +1000 
 
Declare Function TWAIN_SetThreshold Lib "Eztwain.dll" (ByVal dThresh As Double) As Long 
' Try to set the threshold for black and white scanning. 
' Should only affect 1-bit scans i.e. PixelType == TWPT_BW. 
' The TWAIN default threshold value is 128. 
' After staring at the TWAIN 1.6 spec for a while, I imagine that it implies 
' that for 8-bit samples, values >= nThresh are thresholded to 1, others to 0. 
 
Declare Function TWAIN_GetCurrentThreshold Lib "Eztwain.dll" () As Double 
' Try to get and return the current value (MSG_GETCURRENT) of the 
' ICAP_THRESHOLD capability.  If this fails for any reason, it 
' will return -1.  *VERSIONS BEFORE 2.65 RETURNED 128.0* 
 
Declare Sub TWAIN_SetAutoDeskew Lib "Eztwain.dll" (ByVal nMode As Long) 
' Select the 'auto-deskew' mode. 
' Auto-deskew attempts to straighten up scans that are slightly crooked, 
' up to about 10 degrees. 
' The currently defined modes are: 
'  0   - no auto deskew. 
'  1   - auto deskew using EZTwain software algorithms 
 
Declare Function TWAIN_GetAutoDeskew Lib "Eztwain.dll" () As Long 
' Return the current AutoDeskew mode. 
 
Declare Function TWAIN_SetXferMech Lib "Eztwain.dll" (ByVal mech As Long) As Long 
Declare Function TWAIN_XferMech Lib "Eztwain.dll" () As Long 
' Try to set or get the transfer mode - one of the following: 
Global Const XFERMECH_NATIVE = 0 
Global Const XFERMECH_FILE = 1 
Global Const XFERMECH_MEMORY = 2 
' You should not need to set this mode directly - using 
' TWAIN_Acquire, TWAIN_AcquireNative and TWAIN_AcquireFile will set 
' the appropriate transfer mode for you. 
 
Declare Function TWAIN_SupportsFileXfer Lib "Eztwain.dll" () As Long 
' Returns TRUE(1) if the open DS claims to support file transfer mode (XFERMECH_FILE) 
' Returns FALSE(0) otherwise. 
' This mode is optional.  If TRUE, you can use AcquireFile. 
 
Declare Function TWAIN_SetPaperSize Lib "Eztwain.dll" (ByVal nPaper As Long) As Long 
' See TWSS_* in TWAIN.H 
Global Const PAPER_NONE = 0 
Global Const PAPER_A4LETTER = 1 
Global Const PAPER_B5LETTER = 2 
Global Const PAPER_USLETTER = 3 
Global Const PAPER_USLEGAL = 4 
Global Const PAPER_A5 = 5 
Global Const PAPER_B4 = 6 
Global Const PAPER_B6 = 7 
Global Const PAPER_USLEDGER = 9 
Global Const PAPER_USEXECUTIVE = 10 
Global Const PAPER_A3 = 11 
Global Const PAPER_B3 = 12 
Global Const PAPER_A6 = 13 
Global Const PAPER_C4 = 14 
Global Const PAPER_C5 = 15 
Global Const PAPER_C6 = 16 
 
'-------- Document Feeder ------- 
 
Declare Function TWAIN_HasFeeder Lib "Eztwain.dll" () As Long 
' Return TRUE(1) if the source indicates it has a document feeder. 
' Note: A FALSE(0) is returned if the source does not handle this inquiry. 
 
Declare Function TWAIN_IsFeederSelected Lib "Eztwain.dll" () As Long 
' Return TRUE(1) if the document feeder is selected. 
 
Declare Function TWAIN_SelectFeeder Lib "Eztwain.dll" (ByVal bYes As Long) As Long 
' (Try to) select or deselect the document feeder. 
' The document feeder, if any, is selected if bYes is non-zero. 
' The flatbed, if any, is selected if bYes is zero. 
' Note: A few of the scanners that have both a flatbed and 
' a feeder ignore this request in some circumstances. 
' Return TRUE(1) if successful, FALSE(0) otherwise. 
 
Declare Function TWAIN_IsAutoFeedOn Lib "Eztwain.dll" () As Long 
' Return TRUE(1) if automatic feeding is enabled, otherwise FALSE(0). 
' Make sure the feeder is selected before calling this function. 
 
Declare Function TWAIN_SetAutoFeed Lib "Eztwain.dll" (ByVal bYes As Long) As Long 
' (Try to) turn on/off automatic feeding thru the feeder. 
' Return TRUE(1) if successful, FALSE(0) otherwise. 
' This function selects the feeder, so to start scanning 
' pages from an ADF, just do: TWAIN_SetAutoFeed(TRUE). 
 
Declare Function TWAIN_IsFeederLoaded Lib "Eztwain.dll" () As Long 
' Return TRUE(1) if there are documents in the feeder. 
' Make sure the feeder is selected before calling this function. 
 
Declare Function TWAIN_SetAutoScan Lib "Eztwain.dll" (ByVal bYes As Long) As Long 
' Setting this to TRUE gives the scanner permission to 'scan ahead' 
' i.e. to pull pages from the feeder and scan them before 
' they have been requested.  On high-speed scanners, you may 
' have to enable AutoScan to achieve the maximum scanning rate. 
' Returns TRUE(1) if successful, FALSE(0) otherwise. 
' This call will fail on most flatbeds & cameras, and some 'feeder' 
' scanners. 
 
'-------- Duplex Scanning ------- 
 
Declare Function TWAIN_GetDuplexSupport Lib "Eztwain.dll" () As Long 
' Query the device for duplex scanning support. 
'   Return values: 
' 0    = no support (or error, or query not recognized) 
' 1    = 1-pass duplex 
' 2    = 2-pass duplex 
 
Declare Function TWAIN_EnableDuplex Lib "Eztwain.dll" (ByVal bYes As Long) As Long 
' Enable (bYes not 0) or disable (bYes=0) duplex scanning. 
' Returns TRUE(1) if successful, FALSE(0) otherwise. 
 
Declare Function TWAIN_IsDuplexEnabled Lib "Eztwain.dll" () As Long 
' Returns TRUE(1) if the device supports duplex scanning 
' and duplex scanning is enabled.  FALSE(0) otherwise. 
 
'--------- Other 'exotic' capabilities -------- 
 
Declare Function TWAIN_HasControllableUI Lib "Eztwain.dll" () As Long 
' Return 1 if source claims UI can be hidden (see SetHideUI above) 
' Return 0 if source says UI *cannot* be hidden 
' Return -1 if source (pre TWAIN 1.6) cannot answer the question. 
 
Declare Function TWAIN_SetIndicators Lib "Eztwain.dll" (ByVal bVisible As Long) As Long 
' Tell the source to show (hide) progress indicators during acquisition. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_Compression Lib "Eztwain.dll" () As Long 
Declare Function TWAIN_SetCompression Lib "Eztwain.dll" (ByVal compression As Long) As Long 
' Set/Get compression style for transferred data 
' Set returns TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_Tiled Lib "Eztwain.dll" () As Long 
Declare Function TWAIN_SetTiled Lib "Eztwain.dll" (ByVal bTiled As Long) As Long 
' Set/Get whether source does memory xfer via strips or tiles. 
' bTiled = TRUE if it uses tiles for transfer. 
' Set returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_PlanarChunky Lib "Eztwain.dll" () As Long 
Declare Function TWAIN_SetPlanarChunky Lib "Eztwain.dll" (ByVal shape As Long) As Long 
' Set/Get current pixel shape (TWPC_CHUNKY or TWPC_PLANAR), or -1. 
' Set returns TRUE(1) for success, FALSE(0) for failure. 
 
Global Const CHUNKY_PIXELS = 0 
Global Const PLANAR_PIXELS = 1 
 
Declare Function TWAIN_PixelFlavor Lib "Eztwain.dll" () As Long 
Declare Function TWAIN_SetPixelFlavor Lib "Eztwain.dll" (ByVal flavor As Long) As Long 
' Set/Get pixel 'flavor' - whether a '0' pixel value means black or white: 
' Set returns: TRUE(1) for success, FALSE(0) for failure. 
 
Global Const CHOCOLATE_PIXELS = 0 
Global Const VANILLA_PIXELS = 1 
 
 
Declare Function TWAIN_SetLightPath Lib "Eztwain.dll" (ByVal bTransmissive As Long) As Long 
' Tries to select transparent or reflective media on the open source. 
' A parameter of TRUE(1) means transparent, FALSE(0) means reflective. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_SetAutoBRight Lib "Eztwain.dll" (ByVal bOn As Long) As Long 
Declare Function TWAIN_SetGamma Lib "Eztwain.dll" (ByVal dGamma As Double) As Long 
Declare Function TWAIN_SetShadow Lib "Eztwain.dll" (ByVal d As Double) As Long 
Declare Function TWAIN_SetHighlight Lib "Eztwain.dll" (ByVal d As Double) As Long 
' Set auto-bRight$ness, gamma, shadow, and highlight values. 
' Refer to the TWAIN specification for definitions of these settings. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
'--------- Image Layout (Region of Interest) -------- 
 
Declare Sub TWAIN_SetRegion Lib "Eztwain.dll" (ByVal l As Double, ByVal t As Double, ByVal r As Double, ByVal b As Double) 
' Specify the region to be acquired, in current unit of measure. 
' This is the recommended most-general way to scan a region. 
' Tries to use TWAIN_SetImageLayout and TWAIN_SetFrame (see below). 
' If the device ignores those, the specified region is extracted 
' after each scan completes, by software cropping. (DIB_RegionCopy) 
' In other words, this call should *always* produce scans of 
' the requested region, unless you specify a region in inches or 
' centimeters and the device is a camera whose only unit is pixels. 
 
Declare Sub TWAIN_ResetRegion Lib "Eztwain.dll" () 
' Clear any region set with TWAIN_SetRegion above. 
 
Declare Function TWAIN_SetImageLayout Lib "Eztwain.dll" (ByVal l As Double, ByVal t As Double, ByVal r As Double, ByVal b As Double) As Long 
' Specify the area to scan, sometimes called the ROI (Region of Interest) 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
' This call is only valid in State 4. 
' L, T, R, B = distance to Left$, top, Right$, and bottom edge of 
' area to scan, measured in the current unit of measure, 
' from the top-Left$ corner of the 'original page' (TWAIN 1.6 8-22) 
 
Declare Function TWAIN_GetImageLayout Lib "Eztwain.dll" (ByRef l As Double, ByRef t As Double, ByRef r As Double, ByRef b As Double) As Long 
Declare Function TWAIN_GetDefaultImageLayout Lib "Eztwain.dll" (ByRef l As Double, ByRef t As Double, ByRef r As Double, ByRef b As Double) As Long 
' Get the current or default (power-on) area to scan. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
' This call is valid in States 4-6. 
' Supposedly the returned values (see above) 
' are in the current unit of measure (ICAP_UNITS), but I observe that 
' many DS's ignore ICAP_UNITS when dealing with Image Layout. 
 
Declare Function TWAIN_ResetImageLayout Lib "Eztwain.dll" () As Long 
' Reset the area to scan to the default (power-on) settings. 
' This call is only valid in State 4. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
 
' Closely related: 
Declare Function TWAIN_SetFrame Lib "Eztwain.dll" (ByVal l As Double, ByVal t As Double, ByVal r As Double, ByVal b As Double) As Long 
' This is an alternative way to set the scan area. 
' Some scanners will respond to this instead of SetImageLayout. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
' This call is only valid in State 4. 
' L, T, R, B = distance to Left$, top, Right$, and bottom edge of 
' area to scan, measured in the current unit of measure, 
 
 
'--------- Tone Response Curves -------- 
 
Declare Function TWAIN_SetGrayResponse Lib "Eztwain.dll" (ByRef pcurve As Long) As Long 
' Define a translation of gray pixel values. 
' When device digitizes a pixel with value V, that 
' pixel is translated to value pcurve[V] before it 
' is returned to the application. 
' Device must be open (State 4), 
' Current PixelType must be TWPT_GRAY or TWPT_RGB, 
' current BitDepth should be 8. 
' pcurve must be a table (array, vector) of 256 entries. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_SetColorResponse Lib "Eztwain.dll" (ByRef pred As Long, ByRef pgreen As Long, ByRef pblue As Long) As Long 
' Define a translation of color values. 
' Like TWAIN_SetGrayResponse (above) but separate translation can 
' be applied to each color channel. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
Declare Function TWAIN_ResetGrayResponse Lib "Eztwain.dll" () As Long 
Declare Function TWAIN_ResetColorResponse Lib "Eztwain.dll" () As Long 
' These two functions reset the response curve to map every 
' value V to itself i.e. a 'do nothing' translation. 
' Returns: TRUE(1) for success, FALSE(0) for failure. 
 
'--------- Barcode Recognition ------- 
' *** Beta Feature, contact Dosadi before using *** 
 
Declare Function BARCODE_IsAvailable Lib "Eztwain.dll" () As Long 
' TRUE(1) if barcode recognition is available. 
' Returns FALSE(0) otherwise. 
Declare Function BARCODE_Version Lib "Eztwain.dll" () As Long 
' Return the barcode module version * 100. 
 
Declare Sub BARCODE_License Lib "Eztwain.dll" (ByVal Basis As String, ByVal nKey As Long) 
' Supply your Dosadi Barcode add-on license key. 
' This is necessary to continue using the Dosadi barcode engine 
' after your EZTwain trial license has expired. 
' Note that the EZTwain trial license can be renewed. 
' To purchase a barcode add-on license or renew a trial license, 
' contact Dosadi support: support@dosadi.com 
 
Declare Function BARCODE_IsEngineAvailable Lib "Eztwain.dll" (ByVal nEngine As Long) As Long 
Declare Function BARCODE_SelectEngine Lib "Eztwain.dll" (ByVal nEngine As Long) As Long 
Declare Function BARCODE_SelectedEngine Lib "Eztwain.dll" () As Long 
 
Global Const EZBAR_ENGINE_NONE = 0 
Global Const EZBAR_ENGINE_DOSADI = 1 
Global Const EZBAR_ENGINE_AXTEL = 2 
 
' Note: Use of the Axtel engine requires the separately licensed Axtel 
' Axtel 1D Barcode engine: AXBAR32.DLL - See www.axtel.com 
 
Declare Function BARCODE_SetDirectionFlags Lib "Eztwain.dll" (ByVal nDirFlags As Long) As Long 
Declare Function BARCODE_GetDirectionFlags Lib "Eztwain.dll" () As Long 
Declare Function BARCODE_AvailableDirectionFlags Lib "Eztwain.dll" () As Long 
' Set/Get the directions the engine will scan for barcodes. 
' The default is Left$-to-Right$ ONLY. 
' Scanning for barcodes in multiple directions can slow the 
' recognition process.  BARCODE_SetDirectionFlags will return TRUE if 
' completely successful, FALSE if any direction is invalid or not supported. 
' Setting the direction flags to -1 is interpreted as "select all supported 
' directions." 
 
' Barcode direction flags - can be or'ed together 
Global Const EZBAR_Left_TO_Right = &H1 
Global Const EZBAR_Right_TO_Left = &H2 
Global Const EZBAR_TOP_TO_BOTTOM = &H4 
Global Const EZBAR_BOTTOM_TO_TOP = &H8 
Global Const EZBAR_DIAGONAL = &H10 
' some common combinations: 
Global Const EZBAR_HORIZONTAL = &H3 
Global Const EZBAR_VERTICAL = &HC 
 
Declare Function BARCODE_Recognize Lib "Eztwain.dll" (ByVal hdib As Long, ByVal nMaxCount As Long, ByVal nType As Long) As Long 
' Find and recognize barcodes in the given image. 
' Don't look for more than nMaxCount barcodes (-1 means 'any number') 
' Expect barcodes of the specified type (-1 means 'any recognized type') 
' You can add or 'or' together barcode types. 
' 
' Return values: 
'   n>0    n barcodes found 
'   0      no barcodes found 
'  -1      barcode services not available. 
'  -3      invalid or null image 
 
' Barcode types: 
Global Const EZBAR_EAN_13 = &H1 
Global Const EZBAR_EAN_8 = &H2 
Global Const EZBAR_UPCA = &H4 
Global Const EZBAR_UPCE = &H8 
Global Const EZBAR_CODE_39 = &H10 
Global Const EZBAR_CODE_39FA = &H20 
Global Const EZBAR_CODE_128 = &H40 
Global Const EZBAR_CODE_I25 = &H80 
Global Const EZBAR_CODA_BAR = &H100 
Global Const EZBAR_UCCEAN_128 = &H200 
Global Const EZBAR_CODE_93 = &H400 
Global Const EZBAR_CODE_35 = &H800 
Global Const EZBAR_ANY = -1 
 
' Return the text of the nth barcode recognized by the last BARCODE_Recognize. 
' barcodes are numbered from 0. 
' If there is any problem of any kind, returns the empty string. 
 
Declare Function BARCODE_GetText Lib "Eztwain.dll" (ByVal n As Long, ByVal Text As String) As Long 
' Get the text of the nth barcode recognized by the last BARCODE_Recognize. 
' Please allow 64 characters in your text buffer.  Use a smaller buffer 
' only if you *know* that the barcode type is limited to shorter strings. 
 
Declare Function BARCODE_Type Lib "Eztwain.dll" (ByVal n As Long) As Long 
' Return the type of the nth barcode recognized. 
 
Declare Function BARCODE_GetRect Lib "Eztwain.dll" (ByVal n As Long, ByRef l As Double, ByRef t As Double, ByRef r As Double, ByRef b As Double) As Long 
' Get the rectangle bounding the nth barcode found in the last BARCODE_Recognize. 
' Returns TRUE(1) if successful, FALSE(0) otherwise.  The only likely cause 
' of a FALSE return would be an invalid value of n, or a null reference. 
' L    = Left$ edge 
' T    = top edge 
' R    = Right$ edge 
' B    = bottom edge 
 
'--------- Fun With Containers -------- 
 
' Capability values are passed thru the TWAIN API in complex global 
' memory structures called 'containers'.  EZTWAIN abstracts these 
' containers with a handle (an integer) called an HCONTAINER. 
' If you are coding in VB or similar, this is a 32-bit integer. 
' The following functions provide reasonably comprehensive access 
' to the contents of containers.  See also TWAIN_Get, TWAIN_Set. 
' 
' There are four shapes of containers, which I call 'formats'. 
' Depending on its format, a container holds some 'items' - these 
' are simple data values, all the same type in a given container. 
' Item types are enumerated by TWTY_* 
 
' Container formats, same codes as in TWAIN.H 
Global Const TWON_ARRAY = 3 
Global Const TWON_ENUMERATION = 4 
Global Const TWON_ONEVALUE = 5 
Global Const TWON_RANGE = 6 
 
 
Declare Sub CONTAINER_Free Lib "Eztwain.dll" (ByVal hcon As Long) 
' Free the memory and resources of a capability container. 
 
Declare Function CONTAINER_Copy Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Create an exact copy of the container. 
 
Declare Function CONTAINER_Equal Lib "Eztwain.dll" (ByVal hconA As Long, ByVal hconB As Long) As Long 
' Return TRUE (1) iff all properties of hconA and hconB are the same. 
 
Declare Function CONTAINER_Format Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Return the 'format' of this container: TWON_ONEVALUE, etc. 
 
Declare Function CONTAINER_ItemCount Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Return the number of values in the container. 
' For a ONEVALUE, return 1. 
 
Declare Function CONTAINER_ItemType Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Return the item type (what exact kind of values are in the container.) 
' See the TWTY_* definitions in TWAIN.H 
 
Declare Function CONTAINER_TypeSize Lib "Eztwain.dll" (ByVal nItemType As Long) As Long 
' Return the size in bytes of an item of the specified type (TWTY_*) 
 
Declare Sub CONTAINER_GetStringValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long, ByVal sText As String) 
Declare Function CONTAINER_FloatValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long) As Double 
Declare Function CONTAINER_IntValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long) As Long 
' Get the value of the nth item in the container. 
' n is forced into the range 0 to ItemCount(hcon)-1. 
' For string values, if the container items are not strings, they 
' are converted to an equivalent string (e.g. "TRUE", "23", "2.37", etc.) 
 
 
Declare Function CONTAINER_ContainsValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal d As Double) As Long 
' Return TRUE(1) if the value d is one of the items in the container. 
Declare Function CONTAINER_FindValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal d As Double) As Long 
' Return the 0-origin index of the value d in the container. 
' Return -1 if not found. 
 
Declare Function CONTAINER_CurrentValue Lib "Eztwain.dll" (ByVal hcon As Long) As Double 
Declare Function CONTAINER_DefaultValue Lib "Eztwain.dll" (ByVal hcon As Long) As Double 
' Return the container's current or power-up (default) value. 
' Array containers do not have these and will return -1.0. 
' OneValue containers always return their (one) value. 
 
Declare Function CONTAINER_DefaultIndex Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
Declare Function CONTAINER_CurrentIndex Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Return the index of the Default or Current value. 
' Works on Enumerations, Ranges and OneValues. 
' (Always returns 0 for a OneValue) 
' Returns -1 for an Array. 
 
 
Declare Function CONTAINER_MinValue Lib "Eztwain.dll" (ByVal hcon As Long) As Double 
Declare Function CONTAINER_MaxValue Lib "Eztwain.dll" (ByVal hcon As Long) As Double 
Declare Function CONTAINER_StepSize Lib "Eztwain.dll" (ByVal hcon As Long) As Double 
' Return the three parameters that define a Range container. 
' Returns -1.0 if the container is not a Range. 
 
' The following four functions create containers from scratch: 
' nItemType is one of the TWTY_* item types from TWAIN.H 
' nItems is the number of items, in an array or enumeration. 
' dMin, dMax, dStep are the beginning, ending, and step value of a range. 
Declare Function CONTAINER_OneValue Lib "Eztwain.dll" (ByVal nItemType As Long, ByVal dVal As Double) As Long 
Declare Function CONTAINER_Range Lib "Eztwain.dll" (ByVal nItemType As Long, ByVal dMin As Double, ByVal dMax As Double, ByVal dStep As Double) As Long 
Declare Function CONTAINER_Array Lib "Eztwain.dll" (ByVal nItemType As Long, ByVal nItems As Long) As Long 
Declare Function CONTAINER_Enumeration Lib "Eztwain.dll" (ByVal nItemType As Long, ByVal nItems As Long) As Long 
 
Declare Function CONTAINER_SetItem Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long, ByVal dVal As Double) As Long 
Declare Function CONTAINER_SetItemString Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long, ByVal sVal As String) As Long 
Declare Function CONTAINER_SetItemFrame Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long, ByVal l As Double, ByVal t As Double, ByVal r As Double, ByVal b As Double) As Long 
' Set the nth item of the container to dVal or pzText, or frame(l,t,r,b). 
' NOTE: A OneValue is treated as an array with 1 element. 
' Return TRUE(1) if successful. FALSE(0) for error such as: 
'    The container is not an array, enumeration, or onevalue 
'    n < 0 or n >= CONTAINER_ItemCount(hcon) 
'    the value cannot be represented in this container's ItemType. 
 
Declare Function CONTAINER_SelectDefaultValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal dVal As Double) As Long 
Declare Function CONTAINER_SelectDefaultItem Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long) As Long 
Declare Function CONTAINER_SelectCurrentValue Lib "Eztwain.dll" (ByVal hcon As Long, ByVal dVal As Double) As Long 
Declare Function CONTAINER_SelectCurrentItem Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long) As Long 
' Select the current or default value within an enumeration or range, 
' by specifying either the value, or its index. 
' Returns TRUE(1) if successful, FALSE(0) otherwise. 
' This will fail if: 
'    The container is not an enumeration or range. 
'    dVal is not one of the values in the container 
'    n < 0 or n >= CONTAINER_ItemCount(hcon) 
 
Declare Function CONTAINER_DeleteItem Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long) As Long 
' Delete the nth item from an Array or Enumeration container. 
' Returns TRUE(1) for success, FALSE(0) otherwise. Failure causes: 
'   invalid container handle 
'   container is not an array or enumeration 
'   n < 0 or n >= ItemCount(hcon) 
 
Declare Function CONTAINER_InsertItem Lib "Eztwain.dll" (ByVal hcon As Long, ByVal n As Long, ByVal dVal As Double) As Long 
' Insert an item with value dVal into the container at position n. 
' If n < 0, the item is inserted at the end of the container. 
' Return TRUE(1) on success, FALSE(0) on failure. 
' Possible causes of failure: 
'   NULL or invalid container handle 
'   container format is not enumeration or array 
'   memory allocation failed - heap corrupted, or out of memory. 
 
'--- Very low level CONTAINER functions you probably won't need: 
Declare Function CONTAINER_Wrap Lib "Eztwain.dll" (ByVal nFormat As Long, ByVal hcon As Long) As Long 
' Wrap a TWAIN container handle into an HCONTAINER object. 
' Note: *Do Not* free the hcon - it is now owned by the HCONTAINER. 
Declare Function CONTAINER_Unwrap Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Unwrap a TWAIN container from an HCONTAINER object - free the 
' HCONTAINER and return the original TWAIN container handle. 
Declare Function CONTAINER_Handle Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Retrieve the handle of the TWAIN container wrapped in our HCONTAINER 
Declare Function CONTAINER_IsValid Lib "Eztwain.dll" (ByVal hcon As Long) As Long 
' Return TRUE if the argument seems to be a valid HCONTAINER object. 
 
'--------- Low-level Capability Negotiation Functions -------- 
 
' Setting a capability is valid only in State 4 (TWAIN_SOURCE_OPEN) 
' Getting a capability is valid in State 4 or any higher state. 
 
Declare Function TWAIN_Get Lib "Eztwain.dll" (ByVal uCap As Long) As Long 
' Issue a DAT_CAPABILITY/MSG_GET to the open source. 
' Return a capability 'container' - the 'MSG_GET' value of the capability. 
' Use CONTAINER_* functions to examine and modify the container object. 
' Use CONTAINER_Free to release it when you are done with it. 
' A return value of 0 indicates failure:  Call GetConditionCode 
' or ReportLastError above. 
 
Declare Function TWAIN_GetDefault Lib "Eztwain.dll" (ByVal uCap As Long) As Long 
Declare Function TWAIN_GetCurrent Lib "Eztwain.dll" (ByVal uCap As Long) As Long 
' Issue a DAT_CAPABILITY/MSG_GETDEFAULT or MSG_GETCURRENT.  See Get above. 
 
Declare Function TWAIN_Set Lib "Eztwain.dll" (ByVal uCap As Long, ByVal hcon As Long) As Long 
' Issue a DAT_CAPABILITY/MSG_SET to the open source, 
' using the specified capability and container. 
' Return value as for TWAIN_DS 
 
Declare Function TWAIN_Reset Lib "Eztwain.dll" (ByVal uCap As Long) As Long 
' Issue a MSG_RESET on the specified capability. 
' State must be 4.  Returns TRUE(1) if successful, FALSE(0) otherwise. 
 
Declare Function TWAIN_GetCapBool Lib "Eztwain.dll" (ByVal Cap As Long, ByVal bDefault As Long) As Long 
' Issue a DAT_CAPABILITY/MSG_GETCURRENT on the specified capability, 
' assuming the value type is TW_BOOL. 
' If successful, return the returned value.  Otherwise return bDefault. 
' This is only valid in State 4 (TWAIN_SOURCE_OPEN) or higher. 
 
Declare Function TWAIN_SetCapability Lib "Eztwain.dll" (ByVal Cap As Long, ByVal dValue As Double) As Long 
' The most general capability-setting function, it negotiates 
' with the open device to set the given capability to the specified value. 
' If successful, returns TRUE(1), otherwise FALSE(0). 
' There must be a device open and in state 4, or an error is recorded. 
' (See TWAIN_ReportLastError.) 
 
Declare Function TWAIN_SetCapString Lib "Eztwain.dll" (ByVal Cap As Long, ByVal sValue As String) As Long 
' Set the value of a capability that takes a string value. 
' You don't need to specify the 'itemType', EZTwain asks the driver 
' which itemType it wants. 
 
Declare Function TWAIN_SetCapBool Lib "Eztwain.dll" (ByVal Cap As Long, ByVal bValue As Long) As Long 
' Shorthand for TWAIN_SetCapOneValue(cap, TWTY_BOOL, bValue); 
 
Declare Function TWAIN_GetCapFix32 Lib "Eztwain.dll" (ByVal Cap As Long, ByVal dDefault As Double) As Double 
Declare Function TWAIN_GetCapUint16 Lib "Eztwain.dll" (ByVal Cap As Long, ByVal nDefault As Long) As Long 
Declare Function TWAIN_GetCapUint32 Lib "Eztwain.dll" (ByVal Cap As Long, ByVal lDefault As Long) As Long 
 
Declare Function TWAIN_SetCapFix32 Lib "Eztwain.dll" (ByVal Cap As Long, ByVal dVal As Double) As Long 
Declare Function TWAIN_SetCapOneValue Lib "Eztwain.dll" (ByVal Cap As Long, ByVal ItemType As Long, ByVal ItemVal As Long) As Long 
' Do a DAT_CAPABILITY/MSG_SET, on capability 'Cap' (e.g. ICAP_PIXELTYPE, 
' CAP_AUTOFEED, etc.) using a TW_ONEVALUE container with the given item type 
' and value.  Use SetCapFix32 for capabilities that take a FIX32 value, 
' use SetCapOneValue for the various ints and uints.  These functions 
' do not support FRAME or STR items. 
' Return Value: TRUE (1) if successful, FALSE (0) otherwise. 
 
Declare Function TWAIN_SetCapFix32R Lib "Eztwain.dll" (ByVal Cap As Long, ByVal Numerator As Long, ByVal Denominator As Long) As Long 
' Just like TWAIN_SetCapFix32, but uses the value Numerator/Denominator 
' This is useful for languages that make it hard to pass double parameters. 
 
Declare Function TWAIN_GetCapCurrent Lib "Eztwain.dll" (ByVal Cap As Long, ByVal ItemType As Long, ByRef pVal As Any) As Long 
' Do a DAT_CAPABILITY/MSG_GETCURRENT on capability 'Cap'. 
' Copy the current value out of the returned container into *pVal. 
' If the operation fails (the source refuses the request), or if the 
' container is not a ONEVALUE or ENUMERATION, or if the item type of the 
' returned container is incompatible with the expected TWTY_ type in nType, 
' returns FALSE.  If this function returns FALSE, *pVal is not touched. 
 
Declare Function TWAIN_ToFix32 Lib "Eztwain.dll" (ByVal d As Double) As Long 
' Convert a floating-point value to a 32-bit TW_FIX32 value that can be passed 
' to e.g. TWAIN_SetCapOneValue 
Declare Function TWAIN_ToFix32R Lib "Eztwain.dll" (ByVal Numerator As Long, ByVal Denominator As Long) As Long 
' Convert a rational number to a 32-bit TW_FIX32 value. 
' Returns a TW_FIX32 value that approximates Numerator/Denominator 
 
Declare Function TWAIN_Fix32ToFloat Lib "Eztwain.dll" (ByVal nfix As Long) As Double 
' Convert a TW_FIX32 value (as returned from some capability inquiries) 
' to a double (floating point) value. 
 
 
' The following functions support the relatively exotic CUSTOMDSDATA feature 
' introduced in TWAIN 1.7.  This feature, if supported by a device, allows 
' the application to read and set, all the settings of the device 
' simultaneously with one block of data.  *The format of the data is defined 
' by each device* and is undocumented.  So this is just a way to capture 
' a snapshot of a particular device's settings, and then to 
' restore that state at a later time. 
' 
' To find out if a device supports this feature, open the device and see if 
' TWAIN_GetCapBool(CAP_CUSTOMDSDATA, FALSE) returns TRUE. 
' 
' The TWAIN_State() must be 4 or these functions will display an error. 
' 
Declare Function TWAIN_GetCustomDataToFile Lib "Eztwain.dll" (ByVal sFilename As String) As Long 
Declare Function TWAIN_SetCustomDataFromFile Lib "Eztwain.dll" (ByVal sFilename As String) As Long 
' Both functions return TRUE(1) if successful, FALSE(0) otherwise. 
' These functions will display an error message if called outside State 4. 
' In case of failure, call LastErrorCode, ReportLastError, etc. for details. 
' No file extension is assumed, you should provide one, such as ".dat". 
 
'--------- Lowest-level functions for TWAIN protocol -------- 
 
 
Declare Function TWAIN_DS Lib "Eztwain.dll" (ByVal DG As Long, ByVal DAT As Long, ByVal MSG As Long, ByRef pData As Any) As Long 
' Pass the triplet (DG, DAT, MSG, pData) to the open data source if any. 
' Returns TRUE(1) if the result code is TWRC_SUCCESS, FALSE(0) otherwise. 
' The last result code can be retrieved with TWAIN_GetResultCode(), and the 
' corresponding condition code can be retrieved with TWAIN_GetConditionCode(). 
' If no source is open this call will fail, result code TWRC_FAILURE, 
' condition code TWCC_NODS. 
 
Declare Function TWAIN_Mgr Lib "Eztwain.dll" (ByVal DG As Long, ByVal DAT As Long, ByVal MSG As Long, ByRef pData As Any) As Long 
' Pass a triplet to the Data Source Manager (DSM). 
' Returns TRUE(1) for success, FALSE(0) otherwise. 
' See GetResultCode, GetConditionCode, and ReportLastError functions 
' for diagnosing and reporting a TWAIN_Mgr failure. 
' If the Source Manager is not open, this call fails setting result code 
' TWRC_FAILURE, and condition code=TWCC_SEQERROR (triplet out of sequence). 
 
 
'--------- Advanced / Exotic -------- 
 
Declare Function TWAIN_SetImageReadyTimeout Lib "Eztwain.dll" (ByVal nSec As Long) As Long 
' Set the maximum seconds to wait for an image-ready notification, 
' (when one is expected i.e. after an enable) before posting a 
' dialog that says 'Waiting for <device>' - with a Cancel button. 
' Returns the previous setting. 
' ** Default is -1 which disables this feature. 
' With certain scanners there is a long delay between when the scanner 
' is enabled and when it says "ready to scan".  Also, we have found 
' a few scanners that intermittently fail to send "ready to scan" - by 
' setting this timeout, you give your users a way to recover from 
' this failure (otherwise the application has to be forcibly terminated.) 
 
Declare Sub TWAIN_AutoClickButton Lib "Eztwain.dll" (ByVal sButtonName As String) 
' Calling this function before scanning tells EZTwain to attempt to 
' automatically press a button when the device dialog appears. 
' If you pass a null button name, EZTwain tries a number 
' of likely choices (in English) including: 
' "Scan" "Capture" "Acquire" "Scan Now" "Start Scan"  "Start Scanning" 
' Case is ignored in the comparison ("SCAN" and "scan" are equivalent.) 
' This function is useful when you want to automate operation of 
' a device that insists on showing its user interface. 
 
Declare Sub TWAIN_BreakModalLoop Lib "Eztwain.dll" () 
' Expert: If EZTwain is hung inside an Acquire or GetMessage loop waiting for 
' something to happen, this function will break the loop, as if the pending 
' transfer had failed.  TWAIN_State() will be valid, and you will need to 
' call appropriate functions to transition TWAIN as desired. 
 
Declare Sub TWAIN_EmptyMessageQueue Lib "Eztwain.dll" () 
' Expert: Get and process any pending Windows messages for this thread. 
' For example, keystrokes or mouse clicks.  Calling this during 
' long processes will allow the user to interact with the UI. 
' Use only if you understand the message pump. 
 
'--------- Dosadi Special -------- 
 
' Return a string describing the build of EZTWAIN e.g. "Release - Build 6" 
 
Declare Sub TWAIN_GetBuildName Lib "Eztwain.dll" (ByVal sName As String) 
' Like TWAIN_BuildName, but copies the build string into its parameter. 
' The parameter is a string variable (char array in C/C++). 
' You are responsible for allocating room for 128 8-bit characters 
' in the string variable before calling this function. 
 
Declare Function TWAIN_GetSourceIdentity Lib "Eztwain.dll" (ByRef ptwid As Any) As Long 
 
Declare Function TWAIN_GetImageInfo Lib "Eztwain.dll" (ByRef ptwinfo As Any) As Long 
' Issue a DG_IMAGE / DAT_IMAGEINFO / MSG_GET placing the returned data 
' at ptwinfo.  The returned structure is a TW_IMAGEINFO - see twain.h. 
 
Declare Sub TWAIN_LogFile Lib "Eztwain.dll" (ByVal fLog As Long) 
' Turn logging eztwain.log on or off. 
' By default the log file is written to C:\ but this 
' can be overridden, see TWAIN_SetLogFolder below. 
' 
' fLog = 0    close log file and turn off logging 
' The following flags can be combined to enable logging: 
' 1            basic logging of TWAIN and EZTwain operations. 
' 2            flush log constantly (use if EZTwain crashes) 
' 4            log Windows messages flowing through EZTwain 
Global Const EZT_LOG_ON = 1 
Global Const EZT_LOG_FLUSH = 2 
Global Const EZT_LOG_MSGS = 4 
 
 
Declare Sub TWAIN_SetLogFolder Lib "Eztwain.dll" (ByVal sFolder As String) 
' Specify the folder (directory) where the eztwain.log file 
' should be placed.  Default is "c:\" - the root of the C: drive. 
' EZTwain appends a trailing 'slash' if needed. 
' Passing NULL or "" resets to the default: "c:\" 
' If the file cannot be created in this folder, EZTwain tries 
' to create it in the Windows temp folder - this varies somewhat 
' by Windows version, search for the Windows API call GetTempPath. 
 
Declare Sub TWAIN_WriteToLog Lib "Eztwain.dll" (ByVal sText As String) 
' Write text to the EZTwain log file (c:\eztwain.log) 
' If the text does not end with a newline, one is supplied. 
' If logging is turned off, this call has no effect. 
' Logging is controlled by TWAIN_LogFile - see above. 
 
 
Declare Function TWAIN_SelfTest Lib "Eztwain.dll" (ByVal f As Long) As Long 
' Perform internal self-test. 
'   f      ignored for now 
' Return value: 
'   0      success 
'   other  internal test failed. 
 
Declare Function TWAIN_Blocked Lib "Eztwain.dll" () As Long 
' Returns TRUE(1) if processing is inside TWAIN (Source Manager or a DS) 
' FALSE(0) otherwise.  If the former, making any TWAIN call will 
' fail immediately or deadlock the application (Not recommended.) 
 
 
' To save the non-C/C++ folks the hassle of translating from twain.h: 
Global Const CAP_XFERCOUNT = &H1 
Global Const ICAP_COMPRESSION = &H100 
Global Const ICAP_PIXELTYPE = &H101 
Global Const ICAP_UNITS = &H102 
Global Const ICAP_XFERMECH = &H103 
Global Const CAP_AUTHOR = &H1000 
Global Const CAP_CAPTION = &H1001 
Global Const CAP_FEEDERENABLED = &H1002 
Global Const CAP_FEEDERLOADED = &H1003 
Global Const CAP_TIMEDATE = &H1004 
Global Const CAP_SUPPORTEDCAPS = &H1005 
Global Const CAP_EXTENDEDCAPS = &H1006 
Global Const CAP_AUTOFEED = &H1007 
Global Const CAP_CLEARPAGE = &H1008 
Global Const CAP_FEEDPAGE = &H1009 
Global Const CAP_REWINDPAGE = &H100A 
Global Const CAP_INDICATORS = &H100B 
Global Const CAP_SUPPORTEDCAPSEXT = &H100C 
Global Const CAP_PAPERDETECTABLE = &H100D 
Global Const CAP_UICONTROLLABLE = &H100E 
Global Const CAP_DEVICEONLINE = &H100F 
Global Const CAP_AUTOSCAN = &H1010 
Global Const CAP_THUMBNAILSENABLED = &H1011 
Global Const CAP_DUPLEX = &H1012 
Global Const CAP_DUPLEXENABLED = &H1013 
Global Const CAP_ENABLEDSUIONLY = &H1014 
Global Const CAP_CUSTOMDSDATA = &H1015 
Global Const CAP_ENDORSER = &H1016 
Global Const CAP_JOBCONTROL = &H1017 
Global Const CAP_ALARMS = &H1018 
Global Const CAP_ALARMVOLUME = &H1019 
Global Const CAP_AUTOMATICCAPTURE = &H101A 
Global Const CAP_TIMEBEFOREFIRSTCAPTURE = &H101B 
Global Const CAP_TIMEBETWEENCAPTURES = &H101C 
Global Const CAP_CLEARBUFFERS = &H101D 
Global Const CAP_MAXBATCHBUFFERS = &H101E 
Global Const CAP_DEVICETIMEDATE = &H101F 
Global Const CAP_POWERSUPPLY = &H1020 
Global Const CAP_CAMERAPREVIEWUI = &H1021 
Global Const CAP_DEVICEEVENT = &H1022 
Global Const CAP_PAGEMULTIPLEACQUIRE = &H1023 
Global Const CAP_SERIALNUMBER = &H1024 
Global Const CAP_FILESYSTEM = &H1025 
Global Const CAP_PRINTER = &H1026 
Global Const CAP_PRINTERENABLED = &H1027 
Global Const CAP_PRINTERINDEX = &H1028 
Global Const CAP_PRINTERMODE = &H1029 
Global Const CAP_PRINTERSTRING = &H102A 
Global Const CAP_PRINTERSUFFIX = &H102B 
Global Const CAP_LANGUAGE = &H102C 
Global Const CAP_FEEDERALIGNMENT = &H102D 
Global Const CAP_FEEDERORDER = &H102E 
Global Const CAP_PAPERBINDING = &H102F 
Global Const CAP_REACQUIREALLOWED = &H1030 
Global Const CAP_PASSTHRU = &H1031 
Global Const CAP_BATTERYMINUTES = &H1032 
Global Const CAP_BATTERYPERCENTAGE = &H1033 
Global Const CAP_POWERDOWNTIME = &H1034 
Global Const ICAP_AUTOBRight$ = &H1100 
Global Const ICAP_BRightNESS = &H1101 
Global Const ICAP_CONTRAST = &H1103 
Global Const ICAP_CUSTHALFTONE = &H1104 
Global Const ICAP_EXPOSURETIME = &H1105 
Global Const ICAP_FILTER = &H1106 
Global Const ICAP_FLASHUSED = &H1107 
Global Const ICAP_GAMMA = &H1108 
Global Const ICAP_HALFTONES = &H1109 
Global Const ICAP_HIGHLIGHT = &H110A 
Global Const ICAP_IMAGEFILEFORMAT = &H110C 
Global Const ICAP_LAMPSTATE = &H110D 
Global Const ICAP_LIGHTSOURCE = &H110E 
Global Const ICAP_ORIENTATION = &H1110 
Global Const ICAP_PHYSICALWIDTH = &H1111 
Global Const ICAP_PHYSICALHEIGHT = &H1112 
Global Const ICAP_SHADOW = &H1113 
Global Const ICAP_FRAMES = &H1114 
Global Const ICAP_XNATIVERESOLUTION = &H1116 
Global Const ICAP_YNATIVERESOLUTION = &H1117 
Global Const ICAP_XRESOLUTION = &H1118 
Global Const ICAP_YRESOLUTION = &H1119 
Global Const ICAP_MAXFRAMES = &H111A 
Global Const ICAP_TILES = &H111B 
Global Const ICAP_BITORDER = &H111C 
Global Const ICAP_CCITTKFACTOR = &H111D 
Global Const ICAP_LIGHTPATH = &H111E 
Global Const ICAP_PIXELFLAVOR = &H111F 
Global Const ICAP_PLANARCHUNKY = &H1120 
Global Const ICAP_ROTATION = &H1121 
Global Const ICAP_SUPPORTEDSIZES = &H1122 
Global Const ICAP_THRESHOLD = &H1123 
Global Const ICAP_XSCALING = &H1124 
Global Const ICAP_YSCALING = &H1125 
Global Const ICAP_BITORDERCODES = &H1126 
Global Const ICAP_PIXELFLAVORCODES = &H1127 
Global Const ICAP_JPEGPIXELTYPE = &H1128 
Global Const ICAP_TIMEFILL = &H112A 
Global Const ICAP_BITDEPTH = &H112B 
Global Const ICAP_BITDEPTHREDUCTION = &H112C 
Global Const ICAP_UNDEFINEDIMAGESIZE = &H112D 
Global Const ICAP_IMAGEDATASET = &H112E 
Global Const ICAP_EXTIMAGEINFO = &H112F 
Global Const ICAP_MINIMUMHEIGHT = &H1130 
Global Const ICAP_MINIMUMWIDTH = &H1131 
Global Const ICAP_AUTODISCARDBLANKPAGES = &H1134 
Global Const ICAP_FLIPROTATION = &H1136 
Global Const ICAP_BARCODEDETECTIONENABLED = &H1137 
Global Const ICAP_SUPPORTEDBARCODETYPES = &H1138 
Global Const ICAP_BARCODEMAXSEARCHPRIORITIES = &H1139 
Global Const ICAP_BARCODESEARCHPRIORITIES = &H113A 
Global Const ICAP_BARCODESEARCHMODE = &H113B 
Global Const ICAP_BARCODEMAXRETRIES = &H113C 
Global Const ICAP_BARCODETIMEOUT = &H113D 
Global Const ICAP_ZOOMFACTOR = &H113E 
Global Const ICAP_PATCHCODEDETECTIONENABLED = &H113F 
Global Const ICAP_SUPPORTEDPATCHCODETYPES = &H1140 
Global Const ICAP_PATCHCODEMAXSEARCHPRIORITIES = &H1141 
Global Const ICAP_PATCHCODESEARCHPRIORITIES = &H1142 
Global Const ICAP_PATCHCODESEARCHMODE = &H1143 
Global Const ICAP_PATCHCODEMAXRETRIES = &H1144 
Global Const ICAP_PATCHCODETIMEOUT = &H1145 
Global Const ICAP_FLASHUSED2 = &H1146 
Global Const ICAP_IMAGEFILTER = &H1147 
Global Const ICAP_NOISEFILTER = &H1148 
Global Const ICAP_OVERSCAN = &H1149 
Global Const ICAP_AUTOMATICBORDERDETECTION = &H1150 
Global Const ICAP_AUTOMATICDESKEW = &H1151 
Global Const ICAP_AUTOMATICROTATE = &H1152 
 
 
' Container item types: 
Global Const TWTY_INT8 = &H0 
Global Const TWTY_INT16 = &H1 
Global Const TWTY_INT32 = &H2 
Global Const TWTY_UINT8 = &H3 
Global Const TWTY_UINT16 = &H4 
Global Const TWTY_UINT32 = &H5 
Global Const TWTY_BOOL = &H6 
Global Const TWTY_FIX32 = &H7 
Global Const TWTY_FRAME = &H8 
Global Const TWTY_STR32 = &H9 
Global Const TWTY_STR64 = &HA 
Global Const TWTY_STR128 = &HB 
Global Const TWTY_STR255 = &HC 
Global Const TWTY_STR1024 = &HD 
Global Const TWTY_UNI512 = &HE 
 
 
 
' EZTwain History: See History.txt 
 
'Function TWAIN_SourceName() As String 
'    Dim s As String 
'    s = Space$(4096) 
'    Call TWAIN_GetSourceName(s) 
'    TWAIN_SourceName = Left$(s, InStr(s, vbNullChar) - 1) 
'End Function 
 
'Function DIB_PrinterName(ByVal i As Long) As String 
'    Dim s As String 
'    s = Space$(4096) 
'    Call DIB_GetPrinterName(i, s) 
'    DIB_PrinterName = Left$(s, InStr(s, vbNullChar) - 1) 
'End Function 
 
'Function TWAIN_LastErrorText() As String 
'    Dim s As String 
'    s = Space$(4096) 
'    Call TWAIN_GetLastErrorText(s) 
'    TWAIN_LastErrorText = Left$(s, InStr(s, vbNullChar) - 1) 
'End Function 
 
'Function TWAIN_NextSourceName() As String 
'    Dim s As String 
'    s = Space$(4096) 
'    Call TWAIN_GetNextSourceName(s) 
'    TWAIN_NextSourceName = Left$(s, InStr(s, vbNullChar) - 1) 
'End Function 
' 
'Function TWAIN_DefaultSourceName() As String 
'    Dim s As String 
'    s = Space$(4096) 
'    Call TWAIN_GetDefaultSourceName(s) 
'    TWAIN_DefaultSourceName = Left$(s, InStr(s, vbNullChar) - 1) 
'End Function 
 
Function BARCODE_Text(ByVal n As Long) As String 
    Dim s As String 
    s = Space$(4096) 
    Call BARCODE_GetText(n, s) 
    BARCODE_Text = Left$(s, InStr(s, vbNullChar) - 1) 
End Function 
 
Function CONTAINER_StringValue(ByVal hcon As Long, ByVal n As Long) As String 
    Dim s As String 
    s = Space$(4096) 
    Call CONTAINER_GetStringValue(hcon, n, s) 
    CONTAINER_StringValue = Left$(s, InStr(s, vbNullChar) - 1) 
End Function 
 
Function TWAIN_BuildName() As String 
    Dim s As String 
    s = Space$(4096) 
    Call TWAIN_GetBuildName(s) 
    TWAIN_BuildName = Left$(s, InStr(s, vbNullChar) - 1) 
End Function