RbBFBlokpObj _(Q}{VNameStrn sjgEZTwainContInt rEdtRectFu!eSptInt bPGpGrupPbPElGrup4scKyInt VbrEdtRectFu!eSptInt EndGInt EndGInt bClsInt NameStrn sjgEZTwainSizeInt 0bNtrInt PropGrupEncoInt declStrnAvailable As BooleansorcGrupxstsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnAvailable As BooleanntlnStrnntlnStrnEndGInt EndGInt PropGrupEncoInt declStrnEZTwainVersion As StringsorcGrup|stsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnEZTwainVersion As StringntlnStrnntlnStrnEndGInt EndGInt PropGrupEncoInt declStrnfItem As FolderItemsorcGrupx stsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnfItem As FolderItemntlnStrnntlnStrnEndGInt EndGInt PropGrup EncoInt declStrnpic As PicturesorcGrupt stsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnpic As PicturentlnStrnntlnStrnEndGInt EndGInt PropGrup EncoInt declStrnlastError As StringsorcGrupx stsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnlastError As StringntlnStrnntlnStrnEndGInt EndGInt PropGrupEncoInt declStrnclassVersion As StringsorcGruppstsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnclassVersion As StringntlnStrnEndGInt EndGInt NoteGrupEncoInt nameStrnAboutflagInt sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnAboutntlnStrn'This class was written by Steve Garman ntlnStrn!http://rb.sgarman.net/sjgeztwain/ntlnStrnntlnStrn:It uses the Public Domain Windows dll EZTW32.dll by DosadintlnStrn1available from http://www.dosadi.com/eztwain1.htmntlnStrn in REALbasic ntlnStrnntlnStrn>This class requires EZTW32.dll to be either in the same folderntlnStrn2as the app executable or to be in the Windows pathntlnStrnntlnStrn:%windir%/system32 is a good choice if looking for a folderntlnStrn2that can be reasonably expected to be in the path.EndGInt EndGInt NoteGrupEncoInt nameStrnWarningflagInt sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnWarningntlnStrn)There are many limitations to this class.ntlnStrnntlnStrn?One of them is that it may lock your application up if the userntlnStrn7asks it to acquire when their TWAIN device is unpluggedntlnStrnntlnStrnBThis depends on the driver for your particular scanner/camera etc.EndGInt EndGInt NoteGrupEncoInt nameStrnUsageflagInt sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt ntlnStrnUsagentlnStrnL EZTW32.dll must be available in the Path or in the same folder as the .exentlnStrn (see About note)ntlnStrnntlnStrnSelectSource MethodntlnStrnO Only needs to be called if the user wishes to change the default TWAIN sourcentlnStrn% Displays the standard Select dialogntlnStrn, (Works by calling TWAIN_SelectImageSource)ntlnStrnntlnStrnAll Acquire functionsntlnStrn- Call the currently selected source's dialogntlnStrnE Attempt to populate the class's public .pic property with a picturentlnStrn* Return True on success, False on falure.ntlnStrnL Offer the reason for failure as a string in the public .lastError propertyntlnStrnntlnStrn8AcquireNative Method (not available before 2006 version)ntlnStrn? Populates the .pic picture directly with no intervening stepsntlnStrn( (Works by calling TWAIN_AcquireNative)ntlnStrnntlnStrnAcquireToClipboard MethodntlnStrne Captures the image to the system clipboard so it can be pasted into external applications like PainntlnStrn( Also populates .pic from the clipboardntlnStrn- (Works by calling TWAIN_AcquireToClipboard)ntlnStrnntlnStrnAcquireToFile MethodntlnStrn[ Takes an optional parameter which is a FolderItem pointing to the bmp file to be created.ntlnStrn# Captures the image to a .bmp filentlnStrnP Offers a public property .fItem as a FolderItem pointing to the file created.sntlnStrn/ Also populates .pic using fItem.OpenAsPicturentlnStrn, (Works by calling TWAIN_AcquireToFilename)EndGInt EndGInt MethGrupEncoInt nameStrn ConstructorparmStrnrsltStrnflagInt sorcGrup$stsrInt stscInt ndsrInt ndscInt EncoInt srclStrnSub Constructor()srclStrn#Const thisModule = " - Constructor"srclStrn#If TargetWin32srclStrn>Declare Function TWAIN_IsAvailable Lib "EZTW32.dll" As IntegersrclStrn>Declare Function TWAIN_EasyVersion Lib "EZTW32.dll" As IntegersrclStrnDim ret As IntegersrclStrnsrclStrnIf TWAIN_IsAvailable = 1 ThensrclStrnSelf.Available = TruesrclStrnret = TWAIN_EasyVersionsrclStrn)EZTwainVersion = Format(ret / 100,"0.00")srclStrnElsesrclStrn@reportError "TWAIN Source Manager cannot be loaded" + thisModulesrclStrnEnd IfsrclStrnsrclStrn#ElsesrclStrn5reportError "Available for Windows only" + thisModulesrclStrn#EndIfsrclStrnsrclStrnEnd SubEndGInt EndGInt MethGrupEncoInt nameStrn AcquireToFileparmStrnf As Folderitem = NilrsltStrnBooleanflagInt sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt srclStrn8Function AcquireToFile(f As Folderitem = Nil) As BooleansrclStrnDim retVal As BooleansrclStrnDim i As IntegersrclStrn$Const thisModule = "- AcquireToFile"srclStrn#If TargetWin32srclStrnIf Self.Available ThensrclStrnlDeclare Function TWAIN_AcquireToFilename Lib "EZTW32.dll"(hwndApp As Integer, pszFile As CString) As IntegersrclStrnsrclStrnIf f <> Nil ThensrclStrn fItem = fsrclStrnElseif fItem Is Nil ThensrclStrn3fItem = TemporaryFolder.Child("sjgeztwaintemp.bmp")srclStrnEnd IfsrclStrnIf fItem <> Nil ThensrclStrn1i = TWAIN_AcquireToFilename(0,fItem.AbsolutePath)srclStrn If i = 0 ThensrclStrnIf fItem.Exists ThensrclStrnpic = fItem.OpenAsPicturesrclStrnIf pic <> Nil ThensrclStrn retVal = TruesrclStrnEnd IfsrclStrnElsesrclStrn+reportError "File not created" + thisModulesrclStrnEnd IfsrclStrnElsesrclStrn Select Case isrclStrnCase -1srclStrnLreportError "Acquire failed OR user cancelled File Save dialog" + thisModulesrclStrnCase -2srclStrnSreportError "file open error (invalid path or name, or access denied)" + thisModulesrclStrnCase -3srclStrnRreportError "(weird) unable to lock DIB - probably an invalid handle" + thisModulesrclStrnCase -4srclStrnRreportError "writing BMP data failed, possibly output device is full" + thisModulesrclStrn End SelectsrclStrnEnd IfsrclStrnElsesrclStrn)reportError "Nil FolderItem" + thisModulesrclStrnEnd IfsrclStrnIf retVal = False Then srclStrn pic = NilsrclStrnEnd IfsrclStrnEnd IfsrclStrn#EndIfsrclStrn Return retValsrclStrnsrclStrn End FunctionEndGInt EndGInt MethGrupdEncoInt nameStrnAcquireToClipboardparmStrnrsltStrnBooleanflagInt sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt srclStrn(Function AcquireToClipboard() As BooleansrclStrnDim retVal As BooleansrclStrnDim i As IntegersrclStrnDim clp As ClipboardsrclStrn)Const thisModule = "- AcquireToClipboard"srclStrn#If TargetWin32srclStrnIf Self.Available ThensrclStrnoDeclare Function TWAIN_AcquireToClipboard Lib "EZTW32.dll"(hwndApp As Integer, wPixTypes As Integer) As IntegersrclStrn!i = TWAIN_AcquireToClipboard(0,0)srclStrnclp = New ClipboardsrclStrnIf clp.PictureAvailable ThensrclStrnpic = clp.PicturesrclStrnIf pic <> Nil ThensrclStrn retVal = TruesrclStrnElsesrclStrn3reportError "Nil picture on clipboard" + thisModulesrclStrnEnd IfsrclStrnElsesrclStrn pic = NilsrclStrn2reportError "No picture on clipboard" + thisModulesrclStrnEnd IfsrclStrn clp.ClosesrclStrnEnd IfsrclStrn#EndIfsrclStrn Return retValsrclStrn End FunctionEndGInt EndGInt MethGrupEncoInt nameStrn SelectSourceparmStrnrsltStrnBooleanflagInt sorcGruplstsrInt stscInt ndsrInt ndscInt EncoInt srclStrn"Function SelectSource() As BooleansrclStrnDim retVal As BooleansrclStrn#If TargetWin32srclStrn$Const thisModule = " - SelectSource"srclStrnIf Self.Available ThensrclStrnRDeclare Function TWAIN_SelectImageSource Lib "EZTW32.dll"(x As Integer) As IntegersrclStrn&If TWAIN_SelectImageSource(0) = 1 ThensrclStrn retVal = TruesrclStrnEnd IfsrclStrn9reportError "TWAIN_SelectImageSource failed" + thisModulesrclStrnEnd IfsrclStrn#EndIfsrclStrn Return retValsrclStrn End FunctionEndGInt EndGInt MethGrupPEncoInt nameStrn reportErrorparmStrn txt As StringrsltStrnflagInt !sorcGrupstsrInt stscInt ndsrInt ndscInt EncoInt srclStrnSub reportError(txt As String)srclStrndim d as new DatesrclStrn0self.lastError = txt + EndOfLine + d.SQLDateTimesrclStrnEnd SubEndGInt EndGInt IntrStrnPadnPadn****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************EOF!