[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? :ehh:
All help would really be appreciated :D
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
Re: Help me understand the code (callbacks mainly)
Quote:
Originally Posted by
Milk
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 :mad:
There must be something else in the code that needs a change :sick:
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.
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! :D