Page 1 of 1

Twain32d

Posted: Wed Apr 14, 2004 12:08 pm
by Skipsy
Hi folks,

I have read something about TWAIN32d.dll in the PB archives.

Does anybody know where I can get his DLL ?
I can see twain_32.dll in my XP system but I guess this is not the
same :!:

Thks a lot.

Posted: Wed Apr 14, 2004 12:40 pm
by benny
@Skipsy:
If you want to use a Scanner via Twain in PB, maybe this dll fits for you:
http://www.ampsoft.org/data/TwScann.zip
It includes a purebasic-example. The dll is written by A.Miehte. If you have any trouble with the german documentation, just ask!

Posted: Wed Apr 14, 2004 4:35 pm
by Skipsy
Well, I need to drive a digital cam... but it could help for syntax.
Thanks.

Posted: Thu Apr 15, 2004 9:53 am
by benny
Hi Skipsy,

I do not have a digicam ... however I wonder if it is important if a scanner or a digicam is accessed via twain. Nevertheless, I found the following source. It requires this DLL http://www.vbgamer.de/cgi-bin/loadframe ... 0026.shtml

So, maybe you try out this source and probably your digicam is listed in the source-selector-window ?

Code: Select all

;EZ_Twain DLL 
;(W) umsetzung nach PB by Galaxy, 03/2003 

;global für DLL 
Global *TWAIN_IsAvailable 
Global *TWAIN_SelectImageSource 
Global *TWAIN_AcquireToClipboard 
Global *TWAIN_AcquireNative 
Global *TWAIN_WriteNativeToFilename 
Global *TWAIN_FreeNative 

Procedure Twain_Init()         ;dll Init 
OpenLibrary(10,"eztw32.dll") 
*TWAIN_IsAvailable = IsFunction(10,"TWAIN_IsAvailable") 
*TWAIN_SelectImageSource = IsFunction(10,"TWAIN_SelectImageSource") 
*TWAIN_AcquireToClipboard = IsFunction(10,"TWAIN_AcquireToClipboard") 
*TWAIN_AcquireNative = IsFunction(10,"TWAIN_AcquireNative") 
*TWAIN_WriteNativeToFilename = IsFunction(10,"TWAIN_WriteNativeToFilename") 
*TWAIN_FreeNative = IsFunction(10,"TWAIN_FreeNative") 
EndProcedure 

Procedure.l Twain_ScannCheck() 
; Check, ob TWAIN Scanner vorhanden ist 
; 0 = Kein Scanner vorhanden oder kein TWAIN Scanner 
; 1 = OK, Scanner gefunden 

value.l = CallFunctionFast(*TWAIN_IsAvailable) 
ProcedureReturn value 
EndProcedure 

Procedure.l Twain_scanchoice(hwnd) 
; Auswahl des Scanners 
; 0 = Kein Scanner vorhanden / Auswahl abgebrochen 
; 1 = OK, Scanner wurde gewählt 

  value.l = CallFunctionFast(*TWAIN_SelectImageSource,hwnd) 
  ProcedureReturn value 
EndProcedure 


Procedure Twain_ScannToFile(datei.s) 
;scannt als Datei 

  bmp.l = CallFunctionFast(*TWAIN_AcquireNative,0,0) 
          CallFunctionFast(*TWAIN_WriteNativeToFilename,bmp,datei) 
          CallFunctionFast(*TWAIN_FreeNative,bmp) 
ProcedureReturn 0 
EndProcedure 

Procedure TWAIN_ScannToClip() 
;scannt in die Zwischenablage 

CallFunctionFast(*TWAIN_AcquireToClipboard,0,0) 
ProcedureReturn 0 
EndProcedure 


; ******************************************* Twain ***************** 

; demo 
WindowID = OpenWindow(0, 700, 10, 320, 400, #PB_Window_SystemMenu,"Test") 
CreateGadgetList(WindowID()) 


Twain_Init()                        ;dll init 
If Twain_ScannCheck() = 1           ;Scanner erkennen und prüfen 
Twain_scanchoice(WindowID)         ;Scanner wählen 
Twain_ScannToFile("scantest.bmp")  ;Bild scannen 
EndIf 



Repeat 
eventID.l = WaitWindowEvent() 
Until EventID = #PB_EventCloseWindow 
If it doesnt work ... have a look at this dll - it states in the document that it supports cam and scanner :
http://www.ampsoft.de/daten/twjpeg2.zip

Good luck :wink:

Posted: Mon Apr 19, 2004 3:21 pm
by Skipsy
Looks interesting...

Thks a lot.

Posted: Mon Apr 19, 2004 8:05 pm
by Num3
Found this at my personnal archive (someone else wrote it)...

And it works just fine :D

Code: Select all

If OpenLibrary(0, "Twain32d.dll")
  IsAvailable  = IsFunction(0, "TWAIN_IsAvailable")
  SelectImageSorce  = IsFunction(0, "TWAIN_SelectImageSource")
  AcquireToFilename  = IsFunction(0, "TWAIN_AcquireToFilename")
  
Else
  MessageRequester("Error",  "Could Not Open DLL", #MB_ICONERROR)
EndIf


picpath.s  = "C:\pic.bmp"
#cmdSelect  = 1
#cmdScan  = 2
#cmdView  = 3
#img  = 4




hWnd  = OpenWindow(0, (GetSystemMetrics_(#SM_CXSCREEN)-767)/2, (GetSystemMetrics_(#SM_CYSCREEN)-476)/2, 767, 476, #PB_Window_SystemMenu, "Scan")
If hWnd  = 0 Or CreateGadgetList(hWnd)=0
  End
EndIf
ButtonGadget(#cmdSelect,  10, 10, 190, 30, "Select TWAIN driver")
ButtonGadget(#cmdScan,  210, 10, 190, 30, "Scan")

Repeat
  EventID  = WaitWindowEvent()
  Select EventID
    Case #PB_EventGadget
      Select EventGadgetID()
        Case #cmdSelect
          Gosub cmdSelect_Click
        Case #cmdScan
          Gosub cmdScan_Click
          Gosub cmdView
      EndSelect
  EndSelect
Until EventID  = #PB_EventCloseWindow
End

cmdSelect_Click :
result  = CallFunctionFast(SelectImageSorce, hWnd)
Return

cmdScan_Click :
result  = CallFunctionFast(AcquireToFilename, hWnd, picpath)
Return

cmdView :
hImage  = LoadImage(#img, picpath)
If hImage
  StartDrawing(WindowOutput())
  DrawImage(hImage,  10, 50, ImageWidth(), ImageHeight())
  StopDrawing()
EndIf
Return