RbBFBlokpObj _ÿ8NameStrn sjgEZTwain ContInt paswStrnbClsInt bNtrInt CompStrnMethGrup({nameStrn Constructor CompStrnVsblInt sorcGrup”|EncoInt srclStrnSub Constructor() srclStrn#Const thisModule = " - Constructor" srclStrn#If TargetWin32 srclStrnCSoft Declare Function TWAIN_IsAvailable Lib "EZTW32.dll" As Integer srclStrnCSoft Declare Function TWAIN_EasyVersion Lib "EZTW32.dll" As Integer srclStrnDim ret As Integer srclStrnDIf System.IsFunctionAvailable("TWAIN_IsAvailable","EZTW32.dll") ThensrclStrnIf TWAIN_IsAvailable = 1 Then srclStrnSelf.Available = True srclStrnret = TWAIN_EasyVersion srclStrn)EZTwainVersion = Format(ret / 100,"0.00") srclStrnElsesrclStrn@reportError "TWAIN Source Manager cannot be loaded" + thisModulesrclStrnEnd If srclStrnElsesrclStrn/reportError "Unable to access dll" + thisModule srclStrnEnd If srclStrn#Else srclStrn5reportError "Available for Windows only" + thisModule srclStrn#EndIf srclStrnsrclStrnEnd Sub EndGInt |EncoInt AlasStrnflagInt shrdInt parmStrnrsltStrnEndGInt {MethGrup˜}nameStrn AcquireToFile CompStrnVsblInt sorcGrupà~EncoInt srclStrn8Function AcquireToFile(f As Folderitem = Nil) As BooleansrclStrnDim retVal As Boolean srclStrn$Const thisModule = "- AcquireToFile"srclStrn#If TargetWin32 srclStrnIf Self.Available Then srclStrnqSoft Declare Function TWAIN_AcquireToFilename Lib "EZTW32.dll"(hwndApp As Integer, pszFile As CString) As Integer srclStrnDim i As IntegersrclStrnsrclStrnIf f <> Nil ThensrclStrn fItem = f srclStrnElseif fItem Is Nil ThensrclStrn3fItem = TemporaryFolder.Child("sjgeztwaintemp.bmp") srclStrnEnd If srclStrnIf fItem <> Nil ThensrclStrn1i = TWAIN_AcquireToFilename(0,fItem.AbsolutePath) srclStrn If i = 0 Then srclStrnIf fItem.Exists ThensrclStrnpic = fItem.OpenAsPicture srclStrnIf pic <> Nil Then srclStrn retVal = True srclStrnEnd If srclStrnElsesrclStrn+reportError "File not created" + thisModule srclStrnEnd If srclStrnElsesrclStrn Select Case i srclStrnCase -1 srclStrnLreportError "Acquire failed OR user cancelled File Save dialog" + thisModulesrclStrnCase -2 srclStrnSreportError "file open error (invalid path or name, or access denied)" + thisModule srclStrnCase -3 srclStrnRreportError "(weird) unable to lock DIB - probably an invalid handle" + thisModule srclStrnCase -4 srclStrnRreportError "writing BMP data failed, possibly output device is full" + thisModule srclStrn End Select srclStrnEnd If srclStrnElsesrclStrn)reportError "Nil FolderItem" + thisModule srclStrnEnd If srclStrnIf retVal = False Then srclStrn pic = Nil srclStrnEnd If srclStrnEnd If srclStrn#EndIf srclStrn Return retVal srclStrnsrclStrn End FunctionEndGInt ~EncoInt AlasStrnflagInt shrdInt parmStrnf As Folderitem = Nil rsltStrnBoolean EndGInt }MethGrupXnameStrnAcquireToClipboard CompStrnVsblInt sorcGrup´€EncoInt srclStrn(Function AcquireToClipboard() As BooleansrclStrnDim retVal As Boolean srclStrn)Const thisModule = "- AcquireToClipboard" srclStrn#If TargetWin32 srclStrnIf Self.Available Then srclStrntSoft Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.dll"(hwndApp As Integer, wPixTypes As Integer) As IntegersrclStrnDim i As IntegersrclStrnsrclStrn!i = TWAIN_AcquireToClipboard(0,0) srclStrnDim clp As New ClipboardsrclStrnIf clp.PictureAvailable ThensrclStrnpic = clp.Picture srclStrnIf pic <> Nil Then srclStrn retVal = True srclStrnElsesrclStrn3reportError "Nil picture on clipboard" + thisModule srclStrnEnd If srclStrnElsesrclStrn pic = Nil srclStrn2reportError "No picture on clipboard" + thisModule srclStrnEnd If srclStrn clp.Close srclStrnEnd If srclStrn#EndIf srclStrn Return retVal srclStrn End FunctionEndGInt €EncoInt AlasStrnflagInt shrdInt parmStrnrsltStrnBoolean EndGInt MethGrupHnameStrn SelectSourceCompStrnVsblInt sorcGrup¬‚EncoInt srclStrn"Function SelectSource() As Boolean srclStrnDim retVal As Boolean srclStrn#If TargetWin32 srclStrn$Const thisModule = " - SelectSource"srclStrnIf Self.Available Then srclStrnJIf system.IsFunctionAvailable("TWAIN_SelectImageSource","EZTW32.dll") Then srclStrnWSoft Declare Function TWAIN_SelectImageSource Lib "EZTW32.dll"(x As Integer) As Integer srclStrn&If TWAIN_SelectImageSource(0) = 1 Then srclStrn retVal = True srclStrnEnd If srclStrn9reportError "TWAIN_SelectImageSource failed" + thisModule srclStrnEnd If srclStrnEnd If srclStrn#EndIf srclStrn Return retVal srclStrn End FunctionEndGInt ‚EncoInt AlasStrnflagInt shrdInt parmStrnrsltStrnBoolean EndGInt MethGrup ƒnameStrn AcquireNative CompStrnVsblInt sorcGrup x„EncoInt srclStrn#Function AcquireNative() As Boolean srclStrnDim retVal As Boolean srclStrn%Const thisModule = " - AcquireNative" srclStrn#if TargetWin32 srclStrnif self.Available Then srclStrnconst GDI_ERROR = &hFFFFsrclStrn}soft Declare Function SelectPalette Lib "gdi32" (hdc As Integer, hPalette As Integer, bForceBackground As Integer) As Integer srclStrnLsoft Declare Function RealizePalette Lib "gdi32" (hdc As Integer) As IntegersrclStrnLsoft Declare Function GlobalLock Lib "kernel32" (hMem As Integer) As IntegersrclStrnsrclStrnQsoft Declare Function TWAIN_DibDepth Lib "EZTW32.dll"(hdib As Integer) As Integer srclStrnQsoft Declare Function TWAIN_DibWidth Lib "EZTW32.dll"(hdib As Integer) As Integer srclStrnRsoft Declare Function TWAIN_DibHeight Lib "EZTW32.dll"(hdib As Integer) As Integer srclStrnR//Declare Function TWAIN_DibNumColors Lib "EZTW32.dll"(hdib As Integer) As Integer srclStrnoSoft Declare Function TWAIN_AcquireNative Lib "EZTW32.dll"(hwndApp As Integer, wPixTypes As Integer) As Integer srclStrnCSoft Declare Sub TWAIN_FreeNative Lib "EZTW32.dll"(hDib As Integer) srclStrnYsoft Declare Function TWAIN_CreateDibPalette Lib "EZTW32.dll"(hDib As Integer) As Integer srclStrnDSoft Declare Sub TWAIN_DrawDibToDC Lib "EZTW32.dll"(hdc As Integer,_srclStrncdx As Integer,dy As Integer,w As Integer,h As Integer,hdib As Integer, sx As Integer,sy As Integer) srclStrnsrclStrnDim gMem As Integer srclStrnDim DibHandle As IntegersrclStrnDim hPall As IntegersrclStrnsrclStrnDim dpth As Integer srclStrnDim w As IntegersrclStrnDim h As IntegersrclStrnsrclStrngMem = TWAIN_AcquireNative(0,0) srclStrnsrclStrnDibHandle = GlobalLock(gMem)srclStrnif DibHandle = 0 Then srclStrnreportError "GlobalLock failed" srclStrnElsesrclStrn dpth = TWAIN_DibDepth(DibHandle)srclStrnw = TWAIN_DibWidth(DibHandle) srclStrnh = TWAIN_DibHeight(DibHandle) srclStrnsrclStrnpic = New Picture(w,h,dpth) srclStrn Dim g As Graphics = pic.GraphicssrclStrnsrclStrn)hPall = TWAIN_CreateDibPalette(DibHandle) srclStrn' srclStrnDim hdc as Integer srclStrn' srclStrnEif SelectPalette(g.Handle( Graphics.HandleTypeHDC ),hPall,0) = 0 Then srclStrn/reportError "SelectPalette failed" + thisModule srclStrnElsesrclStrnFif RealizePalette(g.Handle( Graphics.HandleTypeHDC )) = GDI_ERROR Then srclStrn0reportError "RealizePalette failed" + thisModulesrclStrnElsesrclStrnKTWAIN_DrawDibToDC(g.Handle( Graphics.HandleTypeHDC ),0,0,w,h,DibHandle,0,0) srclStrn3TWAIN_FreeNative(DibHandle) //This calls GlobalFree srclStrn.retVal = True // Assume success if we get here srclStrnend if srclStrnend if srclStrnend if srclStrnend if srclStrn#endif srclStrn Return retVal srclStrnsrclStrn End FunctionEndGInt „EncoInt AlasStrnflagInt shrdInt parmStrnrsltStrnBoolean EndGInt ƒMethGrupP…nameStrn reportError CompStrnVsblInt sorcGrup¬†EncoInt srclStrnSub reportError(txt As String) srclStrndim d as new Date srclStrn0self.lastError = txt + EndOfLine + d.SQLDateTimesrclStrnEnd Sub EndGInt †EncoInt AlasStrnflagInt !shrdInt parmStrn txt As String rsltStrnEndGInt …NoteGrup¸‡nameStrnAbout CompStrnVsblInt sorcGrupdˆEncoInt ntlnStrnAbout ntlnStrn'This class was written by Steve Garman ntlnStrn!http://rb.sgarman.net/sjgeztwain/ ntlnStrnntlnStrn:It uses the Public Domain Windows dll EZTW32.dll by Dosadi ntlnStrn1available from http://www.dosadi.com/eztwain1.htm ntlnStrn in REALbasic ntlnStrnntlnStrn>This class requires EZTW32.dll to be either in the same folder ntlnStrn2as the app executable or to be in the Windows path ntlnStrnntlnStrn:%windir%/system32 is a good choice if looking for a folder ntlnStrn2that can be reasonably expected to be in the path. EndGInt ˆflagInt EndGInt ‡NoteGrup¨‰nameStrnWarning CompStrnVsblInt sorcGrupTŠEncoInt ntlnStrnWarning ntlnStrn)There are many limitations to this class. ntlnStrnntlnStrn?One of them is that it may lock your application up if the user ntlnStrn7asks it to acquire when their TWAIN device is unplugged ntlnStrnntlnStrnBThis depends on the driver for your particular scanner/camera etc. EndGInt ŠflagInt EndGInt ‰NoteGrupŒ‹nameStrnUsage CompStrnVsblInt sorcGrup8ŒEncoInt ntlnStrnUsage ntlnStrnL EZTW32.dll must be available in the Path or in the same folder as the .exentlnStrn (see About note) ntlnStrnntlnStrnSelectSource Method ntlnStrnO Only needs to be called if the user wishes to change the default TWAIN source ntlnStrn% Displays the standard Select dialog ntlnStrn, (Works by calling TWAIN_SelectImageSource)ntlnStrnntlnStrnAll Acquire functions ntlnStrn- Call the currently selected source's dialog ntlnStrnE Attempt to populate the class's public .pic property with a picture ntlnStrn* Return True on success, False on falure. ntlnStrnL Offer the reason for failure as a string in the public .lastError propertyntlnStrnntlnStrnAcquireNative MethodntlnStrn? Populates the .pic picture directly with no intervening steps ntlnStrn( (Works by calling TWAIN_AcquireNative)ntlnStrnntlnStrnAcquireToClipboard Method ntlnStrne Captures the image to the system clipboard so it can be pasted into external applications like Pain ntlnStrn( 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 file ntlnStrnP Offers a public property .fItem as a FolderItem pointing to the file created.sntlnStrn/ Also populates .pic using fItem.OpenAsPicture ntlnStrn, (Works by calling TWAIN_AcquireToFilename)EndGInt ŒflagInt EndGInt ‹PropGrupTEncoInt declStrnAvailable As BooleanflagInt CompStrnshrdInt EndGInt PropGrupXŽEncoInt declStrnEZTwainVersion As StringflagInt CompStrnshrdInt EndGInt ŽPropGrupTEncoInt declStrnfItem As FolderItem flagInt CompStrnshrdInt EndGInt PropGrupPEncoInt declStrnpic As Picture flagInt CompStrnshrdInt EndGInt PropGrupT‘EncoInt declStrnlastError As String flagInt CompStrnshrdInt EndGInt ‘PropGrup’EncoInt declStrnclassVersion As String flagInt CompStrnshrdInt sorcGrup@“EncoInt srclStrnclassVersion As String srclStrnEndGInt “CPrsGrup@”EncoInt srclStrnSet srclStrnsrclStrnEnd Set EndGInt ”CPrgGrupp•EncoInt srclStrnGet srclStrn-Return "sjgEZTwain for RB2006+ version 1.0.1" srclStrnEnd Get EndGInt •EndGInt ’VwBhGrup8–VwPrGrup0—NameStrnNameVsblInt PrGpStrnID EndGInt —VwPrGrupL˜NameStrnIndex VsblInt PrGpStrnID PValStrn -2147483648 EndGInt ˜VwPrGrup4™NameStrnSuper VsblInt PrGpStrnID EndGInt ™VwPrGrupDšNameStrnLeftVsblInt PrGpStrnPositionPValStrn0 EndGInt šVwPrGrupD›NameStrnTop VsblInt PrGpStrnPositionPValStrn0 EndGInt ›VwPrGrup@œNameStrn Available PrGpStrnBehaviorPValStrn0 EndGInt œVwPrGrup4NameStrnEZTwainVersion PrGpStrnBehaviorEndGInt VwPrGrup8žNameStrnpic PrGpStrnBehaviorPValStrn0 EndGInt žVwPrGrup0ŸNameStrn lastError PrGpStrnBehaviorEndGInt ŸVwPrGrup0 NameStrn classVersionPrGpStrnBehaviorEndGInt  EndGInt –PadnPadnà********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************EOF!