xricht17 / twpp

TWAIN framework for C++11. Makes development of applications and data sources much easier.
MIT License
39 stars 17 forks source link

Twain 1.X support #18

Closed Nonononoki closed 5 years ago

Nonononoki commented 5 years ago

I'm very much a beginner regarding TWAIN, so maybe I missed something important.

Unfortunately, the current TWAIN driver of my scanner is stuck at version 1.9. Following the Application development of the readme, I'm stuck at this line of code:

src.open(); // not hard, is it?

which return the result code 1 for failure. Using the default DS and the DS dialog also returns a failure code. Using the official TWAIN example (targeting the TWAIN version 2.1) on github also returns an error on opening the DS. Therefore my guess is that the TWAIN version of my scanners driver is simply too old.

I'm using: Windows 10 Pro 64-bit Qt 5.7 with the Qt Creator MSVC2015 32-bit Ricoh MP C3004

xricht17 commented 5 years ago

Hi,

TWAIN version should not matter that much thanks to backwards compatibility. The default TWAIN manager is v1.7 or maybe older, and yet it can handle any current TWAIN drivers (sources) and applications.

What about existing applications like IrfanView - can they use your scanner without issues? Maybe the driver is corrupted or incompatible with Windows 10?

There is the possibility to debug the TWAIN protocol, though it involves modification to your Windows directory:

  1. Download the latest TWAINDSM.dll from https://github.com/twain/twain-dsm/tree/master/Releases for Windows, 32 bit (yes 32, not 64).
  2. Rename \Windows\twain_32.dll to e.g. twain_32.dll.old
  3. Copy TWAINDSM.dll from 1. to \Windows\ and rename it to twain_32.dll
  4. Create a new user environment variable TWAINDSM_LOG and set its value to e.g. C:\twain.log
  5. TWAIN messages will now be logged into C:\twain.log
Nonononoki commented 5 years ago

I did everything you said, but no log files are created at all. Yes, I removed the old .dll and replaced it with the lastest one from the link you provided. capture capture

I cannot connect the DS with the twpp classes of this project nor with the ones from the official examples, but strange enough, it works with Twacker, but only if you don't select the TWAIN 2.0 option in the settings.

xricht17 commented 5 years ago

It looks like the driver is badly written, and does not actually conform to TWAIN specs, as it seems to depend on a specific version of TWAIN manager. This issue should be taken to Ricoh.

TWPP does work with it if you remove the new TWAIN manager (TWAINDSM.dll) from your system (C:\Windows and maybe C:\Windows\SysWOW64). Or you can force the use of old manager with mgr.load(true). Either way, make sure the twain_32.dll is the original file, not TWAINDSM.dll in disguise.

Nonononoki commented 5 years ago

Wow, thanks! Using mgr.load(true); solved the issue for me! :)

Nonononoki commented 5 years ago

@xricht17 Unrelated question, could you maybe tell me on how to save the scanned bitmap as a file on the hard drive?

xricht17 commented 5 years ago

Since you already use Qt, what about QImage?

E.g. on Windows:

ImageNativeXfer xfer;
...
auto bmp = xfer.data<BITMAPINFOHEADER>();
QImage img = QImage::fromData(reinterpret_cast<uchar *>(bmp.data()), bmp->biSize + bmp->biSizeImage, "DIB");
img.save("C:\\img.bmp");