Results 1 to 5 of 5

Thread: [RESOLVED] Help me understand the code (callbacks mainly)

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Resolved [RESOLVED] Help me understand the code (callbacks mainly)

    I found some code on the net which copies a file and reports the progress using the CopyFileEx API. The problem is that I don't understand how to use it completely, I am stuck at one step.

    I have posted the code at pastebin since it was about 100 lines.
    http://pastebin.com/7fpGhGBi

    So there is one error in that code:
    Code:
    'void MKV_Chapterizer.AdvancedFileHandling.ProgressChanged(string, string, object, long, long)' has the wrong return type
    I don't understand what to do to solve it, I understand that I should change the ProgressChanged to a function which returns something, but I have no idea what it should return, or why it should return anything?

    All help would really be appreciated

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Help me understand the code (callbacks mainly)

    Just had a quick look. Change the return from void to CopyFileCallbackAction to match the delegate and the callback. The return you provide gives you some control over the copy which you can read up on in the documentation.

    edit: windows data types
    Last edited by Milk; Nov 21st, 2011 at 06:50 PM.
    W o t . S i g

  3. #3

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Help me understand the code (callbacks mainly)

    Quote Originally Posted by Milk View Post
    Just had a quick look. Change the return from void to CopyFileCallbackAction to match the delegate and the callback. The return you provide gives you some control over the copy which you can read up on in the documentation.

    edit: windows data types
    I tried changing the type to CopyFileCallBackAction, but it still gives the same error

    There must be something else in the code that needs a change

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Help me understand the code (callbacks mainly)

    It works for me, this is the code I used...
    Code:
            static void Main(string[] args)
            {
                AdvancedFileHandling.CopyFile(@"c:\test", @"c:\testCopy", CopyFileOptions.None, ProgressChanged);
            }
    
            static CopyFileCallbackAction ProgressChanged(string source, string destination, object state, long totalFileSize, long totalBytesTransferred)
            {
                Console.Write('.');
                return CopyFileCallbackAction.Continue;
            }
    I made ProgressChanged static because I called CopyFile() from a static method.
    W o t . S i g

  5. #5

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Help me understand the code (callbacks mainly)

    I tested again and now it worked! VS must have hung up or something before since the error didn't disappear.

    So thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width