See the question and my original answer on StackOverflow

Well, it's called "managed" for some reason :-) What you can do though is declare WriteFile using P/Invoke, like this:

private void callback(IntPtr buffer, int length)
    FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write);
    int written;
    WriteFile(file.Handle, buffer, length, out written, IntPtr.Zero);

 private static extern bool WriteFile(IntPtr hFile, IntPtr lpBuffer, int NumberOfBytesToWrite, out int lpNumberOfBytesWritten, IntPtr lpOverlapped);