Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is Windows.CopyFile method asynchronous? Here's why...

Status
Not open for further replies.

MagicFrisbee

Programmer
Feb 22, 2006
74
US
Question: Is the Windows.CopyFile method asynchronous? Here's why I'm asking: I copy a file from the network to the users's hard drive. It's a DLL. I then copy another DLL from the network to the hard drive and then call RegisterComServer on it. I get an error message that a dependency file doesn't exist, but the dependency file was the first one I copied. And in this case, no, the first file does not have to be registered. Manually, this all works fine, but programmatically I get that error.

If, however, the dependency is there before the program runs, then the subsequent FileCopy and RegisterComServer functions work just fine.

One thing I've tried after the CopyFile command was this:

Code:
while not FileExists( sFileName ) do ;

But that didn't work. Same error message. Any ideas on what to do, or better, why this isn't working?

GIS Programmer
City of Orem, UT
 
Is the file getting flushed out of the disk cache to disk? You need to make sure that gets done. It probably does though. If you want to check whether it's asynchronous, stick a "MessageDlg" after the copy and wait a second or two before you click the "OK" and you can see.
 
I've done experimenting, but with IIS and my asp files, it takes a while for the indexing service to keep up with file changes, more so if I just copyied a large amount of files anywhere on my drive, I found that XP and above uses memory to buffer harddrive changes to improve changes. I found ticking this off in device manager props does the trick, or I have looked into a DLL call that runs and clears this for me, writes everything that is has to, but theres no knowing when it finished.

%windir%\system32\rundll32.exe advapi32.dll,ProcessIdleTasks

maybe I'm on the wrong line of talking... I've been up for 24hours looking after sick children..

Ross
A Previous Systems Developer
 
An alternative is that you can try coding the copy yourself so you can have control over these factors. Not really all that hard, and the code's pretty short for it. Alternate blockread/blockwrite until your source file hits eof.
 
Ive tryed CopyFile, in a backup program I made, I found the best way is with TFileStream, It saved about 25% of the time taken, and you can incress and decress the buffer that the stream uses.
 
I found the problem. It doesn't have to do with file copying. The problem lies in the third-party COM DLL. It can only be registered through regsvr32, and not through programmatic calls to things like RegisterComServer. Even with the dependency file on the hard drive for several minutes, the call RegisterComServer fails with the same message about the file missing. I have posted a more specific question to the makers and users of the DLL here:


Thanks for your help, programmers, but this is a problem none of us can, or could have, solved. My workaround will probably be to call regsvr32 and wait for it to return, but I don't know how to do that.

GIS Programmer
City of Orem, UT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top