VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 123456[7]8910 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 07:10:58 12/17/01 Mon
Author: Michel
Subject: Re: Problem with scanning
In reply to: Poul Halgaard 's message, "Re: Problem with scanning" on 17:05:52 12/15/01 Sat


Hi Poul,

An access violation in Kernel32.DLL is usually a driver issue. There are DLLs from twain, www.twain.org, and for your driver and you may want to check for updates.

Also, something I have heard by not verified, and that calls to the run-time function Trunc may have strange effects on external DLL's.

If you still get the AV with updated drivers, try a global search/replace in the Envision source code to replace calls of Trunc with SafeTrunc which is below. This will be in the next release of Envision, but I have not tested this effect of this solution.

Best regards,

Michel

(* Some notes about SafeTrunc:

I have had numerous customers complain about our product having problems with Epson (and other) Twain
sources. Our product uses your Twain units to transfer the images from the Twain sources.
In fact, your sample application doesn't even work with most Epson scanners (I recently bought a Perfection
1240U with their Twain 5.00 software to track this down).

So after MUCH debugging, here is what I found....

1. While technically the bug is not in your code, the fix Must involve your code. In fact I was able to fix the
problem with only minor modifications to your code (I am a registered owner of the source).
2. The real problem is the way Borland implemented their trunc function and that external programs (DLL's
such as Twain drivers) often cause floating point exceptions that aren't caught until a Delphi application calls
"trunc".
3. The details are rather difficult to explain in e-mail, but look at the following links....
<a rel=nofollow target=_blank href="http://groups.google.com/groups?q=trunc&hl=en&lr=&safe=off&site=groups">http://groups.google.com/groups?q=trunc&hl=en&lr=&safe=off&site=groups</a>

Just search for "trunc" on any Borland developer site and you will see what I mean.

The "fix" I made (that I encourage you to make to the next release), is to change all "trunc" calls to
"safetrunc". Safetrunc merely does the following:


function SafeTrunc (X: Extended): Int64;
begin
try
result := trunc (x);
except
try
result := trunc (x);
except
raise Exception.Create ('Error in SafeTrunc !');
end;
end;
end;

This works because the first trunc "clears" out the floating point exception that was left around and the second
Trunc then works correctly.

I had already got rid of all references to trunc in our application before because of another DLL doing similar
things to my program. With Twain, it is not only likely, but guaranteed that Twain drivers will cause these
types of Floating Point problems. Therefore it is up to your units to ensure they don't cause problems in the
programs using it.

Thanks for your time,

Andrew Pitts
*)
function SafeTrunc( const X : Extended ): Int64;
begin
try
Result := Trunc(X);
except
try
Result := Trunc(X);
except
raise Exception.Create ('EnMisc unit: Error in SafeTrunc.');
end;
end;
end;


>It happens in TScanner.Acquire - the first call to
>CallTriplet:
>
>function CallTriplet( const pSourceId :
>PTW_IDENTITY;
> const pAppId :
>PTW_IDENTITY;
> const DataGroup : TW_UINT32;
> const DataType : TW_UINT16;
> const Msg : TW_UINT16;
> const pData : TW_MEMREF;
> const pTwainResult : PTW_UINT16;
> const DsmEntry : TDSM_Entry
>) : Boolean;
>var
> TwainResult : TW_UINT16;
> TwStatus : TW_STATUS;
>begin
>
>>>>> IN THIS CALL:
> TwainResult := DSMEntry(
> pAppId, pSourceId,
> DataGroup,
> DataType,
> Msg, pData );
>
>
>Does this help you? Should I send the parametervalues
>- then you could try to call with those values and see
>what happens.
>I did not modify the demo and it also happens if I run
>it from outside Delphi. The AV is in kernal32.dll.
>The TWAIN interface works in other programs.
>
>Rgds Poul

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.