This project has moved. For the latest updates, please go here.

Problems using TWAINDSM.dll

Sep 13, 2016 at 2:53 PM
Hello everyone! I have a problem with the Twaindsm.dll (Twain2).

First of all: sorry for the very long post :(

I have a x64 windows 10 machine, visual studio 2015 professional.

I am using Sample2.

I need Twain2 enabled to access ExtImageInfos.

TWAINDSM.dll files are both present on %windows%\system32 and \syswow64 dirs and are the correct versions (x86, x64).

_Platform.Load() returns a IntPtr.Zero :(

Can't use x64 code (for various reasons), so recompiled the library in x86 mode (AnyCPU may fail?).

_Platform.Load() returns a IntPtr.Zero :(

Have forced c:\windows\system32\twaindsm.dll to be sure (on OpenDSM).

_Platform.Load() returns a IntPtr.Zero :(

If I point to a copy of the twaindsm.dll (and TWAINDSM32.msm on the same dir) files copied elsewhere (also tried with a fresh new downloaded from the sourceforge page) the _Platform.Load() works.

Selected the DS from the dropdown menu, clicked the scan button but nothing happens.

Enabled driver UI, click scan on the Sample2 UI, click scan on the driver UI, opens scan progress but keep going forever.

Enabled TWAINDSM logging, got this:

[150804741 dsm.cpp 2368 0 000022B8] PaperStream IP fi-6130ZLAdj -> Saraff.Twain
[150804741 dsm.cpp 2377 0 000022B8] DG_CONTROL/DAT_NULL/MSG_XFERREADY
[150804741 dsm.cpp 2368 0 000022B8] DSM -> Saraff.Twain
[150804741 dsm.cpp 2377 0 000022B8] DG_CONTROL/DAT_NULL/MSG_XFERREADY
[150804741 dsm.cpp 2432 0 000022B8] TWRC_FAILURE
[150804741 dsm.cpp 2432 0 000022B8] TWRC_FAILURE

Tried setting _twain32.Twain2Enabled to false, everyting works (but not the ExtImageInfos I need, of course).

Debugged _twain32.Acquire():

Pass this.OpenDSM(), pass this.OpenDataSource(), pass this._EnableDataSource() but on the OS switch, it do nothing.

IsTwain2Supported is true.

_srcds is:
{PaperStream IP fi-6130ZLAdj}, Version = {1.30.110.5431 Mar 18 2016}
Id: 3
Manufacturer: "FUJITSU"
ProductFamily: "PaperStream IP"
ProductName: "PaperStream IP fi-6130ZLAdj"
ProtocolMajor: 2
ProtocolMinor: 2
SupportedGroups: Control | Image | DS2
Version: {1.30.110.5431 Mar 18 2016}
Application.MessageLoop is true.

The Twain 32bit sample app works good (of course only if I copy on the same directory twaindsm.dll and TWAINDSM32.msm files).

Any hint?
Coordinator
Sep 13, 2016 at 7:33 PM
Hello, sebamix.
By first part, the problem is not in Saraff.Twain.NET. Try invoke a Marshal.GetLastWin32Error() method after a _Platform.Load().
By second part, try download latest source code.
Marked as answer by SARAFF on 9/24/2016 at 8:20 AM
Sep 14, 2016 at 9:27 AM
Hello and thanks for the quick reply :)

I've download the latest source from GIT.

Right after _Platform.LoadLibrary(fileName) (fileName=C:\Windows\system32\TWAINDSM.dll) i got 1008 (0x000003F0) from Marshal.GetLastWin32Error() and -2147023888 from Marshal.GetHRForLastWin32Error().

1008 is ERROR_NO_TOKEN, don't know what this mean :|

Added SetLastError =true to the LoadLibrary dllimport, error is the same.

Thanks,
S.
Coordinator
Sep 14, 2016 at 3:07 PM
Edited Sep 14, 2016 at 3:10 PM
Hello, sebamix.
In this case, I can help only follow link:
http://stackoverflow.com/questions/16565429/c-sharp-loadlibrary-error-no-token/16566182#16566182