.net - CopyFileEx in windows 7 -


i'm trying use function copyfileex kernel32.dll in windows 7 using .net interop. msdn says: if lpprogressroutine returns progress_stop due user stopping operation, copyfileex return 0 , getlasterror return error_request_aborted. in case, partially copied destination file left intact. on windows xp code works ok, on windows 7 partial file being deleted automatically. have missed something?

using system; using system.runtime.interopservices;  namespace copy {     class program     {         static void main(string[] args)         {             var result = extendedcopy.xcopy("c:/original.rar", "c:/copy.rar");         }     }      class extendedcopy     {         [dllimport("kernel32.dll", setlasterror = true, charset = charset.unicode)]         private static extern bool copyfileex(string lpexistingfilename, string lpnewfilename, copyprogressroutine lpprogressroutine, intptr lpdata, ref int32 pbcancel, copyfileflags dwcopyflags);          delegate copyprogressresult copyprogressroutine(long totalfilesize, long totalbytestransferred, long streamsize, long streambytestransferred, uint dwstreamnumber, copyprogresscallbackreason dwcallbackreason, intptr hsourcefile, intptr hdestinationfile, intptr lpdata);          enum copyprogressresult : uint         {             progress_continue = 0,             progress_cancel = 1,             progress_stop = 2,             progress_quiet = 3         }          enum copyprogresscallbackreason : uint         {             callback_chunk_finished = 0x0,             callback_stream_switch = 0x1         }          [flags]         enum copyfileflags : uint         {             copy_file_fail_if_exists = 0x1,             copy_file_restartable = 0x2,             copy_file_open_source_for_write = 0x4,             copy_file_allow_decrypted_destination = 0x8         }          public static bool xcopy(string oldfile, string newfile)         {             int pbcancel = 0;             return copyfileex(oldfile, newfile, new copyprogressroutine(copyprogresshandler), intptr.zero, ref pbcancel, copyfileflags.copy_file_restartable);         }          private static copyprogressresult copyprogresshandler(long total, long transferred, long streamsize, long streambytetrans, uint dwstreamnumber, copyprogresscallbackreason reason, intptr hsourcefile, intptr hdestinationfile, intptr lpdata)         {             if (transferred > 10000000)             {                 return copyprogressresult.progress_stop;             }             return copyprogressresult.progress_continue;         }     } } 


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -