4

How can I use WIA and Twain in C#? The TWIAIN/C# example found at http://www.codeproject.com/KB/dotnet/twaindotnet.aspx Throws an exception at line 59 on TwainLib.cs "an attempt was made to load a program with an incorrect format." on Vista 64.

I would use WIA but it does not have support for all of the devices I want to use.

Is there a simple way to enable TWAIN support in WIA in C#? I know it can be done but I cannot find any documentation on the subject. I am not looking for a commercial product. I can figure out how to use WIA just fine - but its the fact that I cant enable TWIAN support that is annoying.

Examples in C++/CLI or VB.net are also welcome.

Thanks.

EDIT

Thanks, cristianlibardo. You helped me out a lot and I might just continue to use TWIAN for now. But I am still wanting to use WIA; so I will not accept your answer yet. Here is some more info for people just seeing this post. All are in response to this answer:

Yup, that did it for the TWIAN support; thanks! I still want to use WIA though; but now I have something to work with. However, when I select my USB camera as the source and hit acquire, the app hangs. My camera works on other, commercial, TWIAN applications.

By commenting out the lines 100 though 104 (code that checks to see if "DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );" returns TwRC.Success my Camera now works. I have no idea what this code does; as documentation is next-to-nothing on this subject.

OK; its a const called "CAP_XFERCOUNT" that has something to do with scanning multiple images per session. Makes seance that a camera would not support it.

1
  • 3
    It amuses me that this CodeProject page's code, which was written by some dude in 2001 on Windows 2000 before .NET 1.0 even, seems to be the foundation for every single C#/.NET TWAIN implementation on the Internet. Way to go dude.
    – Tom Kidd
    Mar 10, 2010 at 20:32

1 Answer 1

3

Probably a long shot but have your tried building with x86 as platform target or changing thread apartment state?

4
  • Yup, that did it for the TWIAN support; thanks! I still want to use WIA though; but now I have something to work with. However, when I select my USB camera as the source and hit acquire, the app hangs. My camera works on other, commercial, TWIAN applications.
    – user19302
    Nov 8, 2008 at 1:15
  • 1
    By commenting out the lines 100 though 104 (code that checks to see if "DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );" returns TwRC.Success my Camera now works. I have no idea what this code does; as documentation is next-to-nothing on this subject.
    – user19302
    Nov 8, 2008 at 1:25
  • OK; its a const called "CAP_XFERCOUNT" that has something to do with scanning multiple images per session. Makes seance that a camera would not support it.
    – user19302
    Nov 8, 2008 at 1:30
  • There's a pretty comprehensive spec for twain here: twain.org/docs/TWAIN_2_Spec.pdf
    – Filmund
    Aug 12, 2009 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.