Home › Forums › TWAIN Classic › Application crashes when acquiring image
- This topic has 7 replies, 3 voices, and was last updated 14 years, 5 months ago by jimwatters.
- AuthorPosts
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
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.logWhenever 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.
**************************************************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
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.
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
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
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.
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.
**************************************************- AuthorPosts