jtwain.dll : The jtwain c++ library for windows (32-bit version).

Windows jtwain.dll:

  1. you need (i.e. Windows XP):
    - c:\windows\twain_32.dll OR twain 2.0 c:\windows\system32\TWAINDSM.dll (download 32 bit data source manager from www.twain.org)
    - java sdk i.e. Sun's 1.4.2 which you will find by default in c:\j2sdk1.4.2
    - c:\j2sdk1.4.2\include\jni.h (you need to put these in the compilers search path)
    - c:\j2sdk1.4.2\include\win32\jni_md.h
    - twain.h (www.twain.org)
    - uk_co_mmscomputing_device_twain_jtwain.h
  2. open console and cd to jtwain.cpp directory
  3. compile *.cpp and therefore generate the library jtwain.dll like this (Borland C++ 5.5):
    bcc32 -w-par -tWD -I"c:\borland\bcc55\include" -L"c:\Borland\Bcc55\lib;c:\borland\bcc55\lib\psdk" -e"jtwain.dll" *.cpp
    (Have a look at jtwain.bat)
    If you know and trust me :) you can download jtwain.dll here.
  4. put jtwain.dll into library path of java program (4 possibilities):
    1. use -Djava.library.path=... option, when you start the program.
    2. copy jtwain.dll to the java virtual machine's library folder c:\j2sdk1.4.2\jre\bin (Available for all programs started with this jvm [java virtual machine])
    3. or copy jtwain.dll to the operating system's library folder c:\windows\system32. (Available for all java programs and jvms; Just remember: On a 64 bit system the 32 bit DSM library needs to into the Windows\SysWOW64 folder!)
    4. or use uk.co.mmscomputing.util.JarLib.load(...)

How does it work ? What happens ?

I am using the triple [DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET] to initiate the transfer of an image from the data source to the application.
Windows: The data source will transfer the image as a DIB (Device Independent Bitmap). The DIB is coded as a 1, 4 or 8 bit image with a colour table or as an 24bit RGB image.
bmp.cpp will create first a java.awt.image.IndexColorModel if necessary and then call the jtwain-java-object to create a BufferedImage. After that the cpp-part just copies the data to the BufferedImage.

This means of course that we need to have space for two copies of the image in memory. An A4 page scanned with 24bit and 600dpi is about 100MB !