Get image from scanner c#

1

I want to get image from scanner. I have a simple application in Java, but i have see that not exist a free library to get image directly from scanner. So I have this idea, I create a simple project in C# to get image them call this exe file from java application. So I have find this code on codesource.

http://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner

If I try to run demo application, it found I can get image from scanner. But If I try to run the code project I have this error

System.DllNotFoundException non รจ stata gestita
  IsTransient=false
  Message=Impossibile caricare la DLL 'twain_32.dll': Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita. (Eccezione da HRESULT: 0x8007045A).
  Source=TwainGui
  TypeName=""
  StackTrace:
       in TwainLib.Twain.DSMparent(TwIdentity origin, IntPtr zeroptr, TwDG dg, TwDAT dat, TwMSG msg, IntPtr& refptr)
       in TwainLib.Twain.Init(IntPtr hwndp) in c:\Users\michele.castriotta\Downloads\twaingui_src\TwainGui\TwainLib.cs:riga 58
       in TwainGui.MainFrame..ctor() in c:\Users\michele.castriotta\Downloads\twaingui_src\TwainGui\MainFrame.cs:riga 29
       in TwainGui.MainFrame.Main() in c:\Users\michele.castriotta\Downloads\twaingui_src\TwainGui\MainFrame.cs:riga 234
       in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       in System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

I have open the progect with Visual Studio 2013 then I have set the framework version at 2.0 and I have select x86 as CPU.

The error is in the class TwainLib.cs at this point

TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );

I'm try to copy twain_32.dll directly into debug folder, but the error is the same. The system can't find the library. Where is the error?

If is possible to get image from another language for me is the same.

c#
twain
asked on Stack Overflow Mar 18, 2015 by bircastri

1 Answer

3

It's a permission issue, because the twain_32.dll is located under C:\Windows. If you right-click TwainGui.exe, and select "run as administrator", the app can run normally. enter image description here

If you want to debug the program with admin permission, check the following steps:

  1. create a manifest file
  2. change level to "requireAdministrator"
  3. restart VS2013

enter image description here enter image description here

By the way, you can call C# code directly in Java with jni4net. Here is a tutorial - Java TWAIN with Dynamic .NET TWAIN and jni4net.

answered on Stack Overflow Mar 20, 2015 by yushulx

User contributions licensed under CC BY-SA 3.0