|
-
CopyFileEx API - NullReferenceException
I am trying to use the CopyFileEx API in a VB.NET app and I am getting a
"object reference not set to an instance of an object" error every time I
run.
If I comment out the callback function definition (cb = AddressOf
Me.myCopyProgressRoutine) then it copies the file just fine but of course I
don't have any way to update progress.
I have simplified and included my code below for anybody to look at. I am
totally out of ideas on this one.
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Delegate Function CopyProgressRoutine( _
ByVal TotalFileSize As Long, _
ByVal TotalBytesTransferred As Long, _
ByVal StreamSize As Long, _
ByVal StreamBytesTransferred As Long, _
ByVal dwStreamNumber As Long, _
ByVal dwCallbackReason As Long, _
ByVal hSourceFile As Long, _
ByVal hDestinationFile As Long, _
ByVal lpData As Long _
) As Long
Declare Auto Function CopyFileEx Lib "kernel32.dll" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal lpProgressRoutine As CopyProgressRoutine, _
ByVal lpData As Long, _
ByVal lpBool As Long, _
ByVal dwCopyFlags As Long _
) As Boolean
Public Function myCopyProgressRoutine( _
ByVal TotalFileSize As Long, _
ByVal TotalBytesTransfered As Long, _
ByVal StreamSize As Long, _
ByVal StreamBytesTransferred As Long, _
ByVal dwStreamNumber As Long, _
ByVal dqCallbackReason As Long, _
ByVal hSourceFile As Long, _
ByVal hDestinationFile As Long, _
ByVal lpData As Long _
) As Long
copyForm.ProgressBar.Value = TotalBytesTransfered / TotalFileSize *
100
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cb As CopyProgressRoutine
cb = AddressOf Me.myCopyProgressRoutine
copyForm.Show()
CopyFileEx("c:\eric.log", "c:\logs\eric1.log", cb, 0, False, 0)
copyForm.Hide()
End Sub
End Class
Any ideas as to why the error is occurring?
Thanks,
Eric
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks