TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Application crashes when acquiring image

Forums › TWAIN Classic › Application crashes when acquiring image

  • This topic has 7 replies, 3 voices, and was last updated 11 years, 3 months ago by jimwatters.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • June 23, 2009 at 9:35 am #22505 Reply
    andrewfife
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    Hi All

    I have an application that works with most scanners. I am having a problem with a Visioneer RoadWarrior scanner. The application crashes when transfering the image on the following line of code:

    rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);

    The code is within a try catch, but that doesn’t help. Also, because the application bombs right out, I can’t get the value of rc. I have also tried file transfer mode, but the same thing happens.

    Interestingly, when setting the transfer mode using the following code, I always get rc = failure:

    TwCapability cap = new TwCapability(TwCap.IXferMech, (short)TwIXferMechType.TWSX_NATIVE);
    rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

    This seems to work with other scanners I’ve tried. I have also tested this scanner in Twacker, and it works fine. I have been through the code in Twacker to see what I’m missing, but I don’t see anything. I must be missing something though. Does anyone have any suggestions to why the application would crash when transfering the image, and also why when setting the transfer mode, it always returns failure.

    Also interestingly, when installing the scanner, it installed Visioneer RoadWarrior (which I presume is the twain driver) and WIA-Visioneer RoadWarrior. The WIA scanner seems to work somewhat. I thought WIA wasn’t related to Twain?

    Thanks

    June 23, 2009 at 2:46 pm #24921 Reply
    jimwatters
    Participant
    • Topics - 2
    • Replies - 72
    • Total Posts - 74

    To help figure out what is happenings you could compare the log files generated by twain_32.dll when using your app and twacker.
    The log file is stored in your temp folder
    %temp%twain.log

    Whenever you receive a TWRC_FAILURE you should do a DG_CONTROL / DAT_STATUS / MSG_GET to find out why the previous message failed.

    The problem might be a sequence error. The order of capability negotiation is discussed in the TWAIN spec on p600(A-34). Transfer mode should be negotiated first.

    twain_32.dll provides a method to expose WIA drivers as limited twain drivers. For best TWAIN support use the real TWAIN driver.

    Regards,
    Jim Watters

    **************************************************
    JFL Peripheral Solutions Inc.
    http://www.jflinc.com/
    Your Expert Source of Custom Software and Services
    for TWAIN Applications, Data Sources,
    Peripheral Drivers and Support Software.
    **************************************************

    June 24, 2009 at 1:31 pm #24922 Reply
    andrewfife
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    Thanks for pointing out the log file to me, I didn’t know that was there. Apon inspecting this file I’ve noticed the following differences:

    CAPABILITY, SET, XFERMECH sets rc=1 in my application, 0 in twacker.

    CONTROL, EVENT, PROCESSEVENT sets rc=5 for some reason. In twacker this is 4. When running through the code, it only transfers when rc=4, but for some reason this is 5 in the log.

    IMAGE, IMAGENATIVEXFER, GET is the last line in the log file, so I don’t know what rc is in this case. This is also where the application crashes.

    I also run DG_CONTROL / DAT_STATUS / MSG_GET after setting XFERMECH, and the condition code it returns is 10 – Bad value. Not sure why this is.

    I will double check the sequence, but I did think this was right.

    Thanks

    June 24, 2009 at 1:44 pm #24923 Reply
    andrewfife
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    OK, I’ve fixed the triplet to set the transfer method to native. I changed the code to the following and the last parameter on the capability (TwType.UInt16) seems to have fixed it:

    cap = new TwCapability(TwCap.IXferMech, (short)TwIXferMechType.TWSX_NATIVE, TwType.UInt16);
    rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

    The application still crashes when transfering the image though, which is my biggest problem (rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);)

    Thanks.

    June 24, 2009 at 2:48 pm #24924 Reply
    jimwatters
    Participant
    • Topics - 2
    • Replies - 72
    • Total Posts - 74

    I am not familiar with this framework you are using.
    But look at hbitmap and the DSixfer function.

    passing a bad pointer would cause problems.

    Jim Watters

    July 10, 2009 at 9:30 am #24925 Reply
    andrewfife
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    I have looked at quite a few examples now of scanning and haven’t found a solution to this problem yet. I’m using c# to code in, and thought that maybe my pointers were declared incorrectly or something like that. However, I have found other applications writen in c# and tried scanning through those applications using the same scanner, and they seem to fail as well. I think this may be a limitation of some sort with passing pointers in c# and this particular scanner. As I’ve said, it seems to work with twacker (which is c++). I may have to convert some of my code to c++ in order to get this scanner working.

    Thanks

    November 17, 2009 at 8:55 pm #24926 Reply
    Travis
    Participant
    • Topics - 3
    • Replies - 1
    • Total Posts - 4

    Hello andrewfife,

    I have almost the exact same issue with a Xerox DocuMate 262 scanner. The Twain driver for this scanner was made by Visioneer.

    I am able to get and set capbilities with the scanner just fine. However on the call to transfer to the image (whether showing the UI or not, or whether XferMode is set to Native, Memory, or File) I get an access violation.

    Also to note, this issue only occurs when calling this function from within a .NET application and on a 64 bit operating system, but both the Twain Driver and .NET application are 32 bit. I explicitly make the Application x86 (not using AnyCPU).

    The same driver and application work fine on a 32 bit OS.

    I’m simply passing in the App identity, Source identity, the triplets (DG_CONTROL, DAT_IMAGENATIVEXFER, MSG_GET) and a TW_MEMREF set to NULL. Making this call results in an immediate exception: Access Violation.

    A call to the driver (made just before this one) to get the ImageInfo succeeds which tells me the DLL handle, the function pointer, and the two TW_IDENTITY structures are fine. The only other variable in question is the TW_MEMREF which is supposed to be NULL, so I don’t believe it is the issue either.

    The real kicker is that the exact same code compiled as C++ works perfectly. I have ran both in debuggers (separately), took screen shots of all the values of all the variables and every single one of them are the same.

    The only difference is that the failing code is ran through a .NET application. If you found the resolution to this, please post again.

    November 20, 2009 at 8:05 pm #24927 Reply
    jimwatters
    Participant
    • Topics - 2
    • Replies - 72
    • Total Posts - 74

    Does the following hotFix from Microsoft resolve the issue?
    http://support.microsoft.com/kb/944925/

    Regards,
    Jim Watters

    **************************************************
    JFL Peripheral Solutions Inc.
    http://www.jflinc.com/
    Your Expert Source of Custom Software and Services
    for TWAIN Applications, Data Sources,
    Peripheral Drivers and Support Software.
    **************************************************

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: Reply #24921 in Application crashes when acquiring image
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • Scanner starts transfer when console gets closed (CITRIX)
  • Kodak RFS 3600
  • Didn’t save enough file scan
  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.