Article View: borland.public.cppbuilder.nativeapi
Article #9718Re: CopyFileEx - CopyProgressRoutine - devision by zero
From: Bob Gonder
Date: Sat, 19 Jun 2004 05:47
Date: Sat, 19 Jun 2004 05:47
55 lines
2958 bytes
2958 bytes
Tommy wrote:
>i did some tests, but i wont work. before the copy process starts i call
How does it "won't work"?
Does it compile?
Does it run?
Does it give larger values than you expect?
Smaller?
Sorry, but my mind reading machine is broken.
>
>This wont work because i cant subtract 2 FILETIME.
Yeah, I mentioned that you needed to mess with getting a FT into a
int64. I'm not too proud of the way I did it, but..
typedef union uFT264{
FILETIME ft;
DWORDLONG i64;
}FT264;
static FT264 StartTime;
void updatetime()
{ FT264 now;
FT264 remaining;
FT264 elapsed;
SYSTEMTIME SystemTime;
GetLocalTime( &SystemTime );
SystemTimeToFileTime( &SystemTime, &now.ft );
elapsed.i64 = now.i64 - StartTime.i64;
FileTimeToSystemTime( &elapsed.ft, &SystemTime );
FormatTime( &SystemTime, szCM_U_TIMECOPIED );
remaining.i64 = ((BytesRemaining * (elapsed.i64/10000U)) /
(BytesSoFar+1))*10000U;
FileTimeToSystemTime( &remaining.ft, &SystemTime );
FormatTime( &SystemTime, szCM_U_TIMEREMAINING );
> Another problem ist that
>i cannot follow your idea how to solve. i understand that it is not good to
>divide so often a value by 10million.
What I really think isn't so good, is converting to floating point
when there's no need.
If you keep everything in FILETIME accuracy, then you don't need to
divide my 10 million. Just use FileTimeToSystemTime to convert to
hours:minutes:seconds. But, if you keep everything at FILETIME
accuracy, there's a decent chance the multiply will overflow.
So, dividing the elapsed time by 10,000 reduces the chance of overflow
while still keeping a time accuracy of 1/1000th second. After the
calculation, you need to re-multiply by the same 10,000 to return the
FILETIME to it's original "accuracy" so that FileTimeToSystemTime can
decode it properly.
Technical Details
Message-ID:
<2bj7d0dc8b89se5ibtdm7nntbvsrga2lrt@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40ce2e93@newsgroups.borland.com> <crtsc0pp05ki34cqsvkgsj721eei6g7obh@4ax.com> <40cef067$1@newsgroups.borland.com> <8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com> <40d3589b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9a3709a4832c0e51 X-Google-Attributes: gid10cc67,public From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: CopyFileEx - CopyProgressRoutine - devision by zero Date: Fri, 18 Jun 2004 22:47:01 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <2bj7d0dc8b89se5ibtdm7nntbvsrga2lrt@4ax.com> References: <40ce2e93@newsgroups.borland.com> <crtsc0pp05ki34cqsvkgsj721eei6g7obh@4ax.com> <40cef067$1@newsgroups.borland.com> <8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com> <40d3589b@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 206.107.223.205 X-Trace: newsgroups.borland.com 1087624019 206.107.223.205 (18 Jun 2004 22:46:59 -0700) Lines: 58 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail