顺便借问有没有什么材料或者书籍对各种API及其使用的结构有详细解释?
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByVal lpFileOp As SHFILEOPSTRUCT) As Integer
Structure SHFILEOPSTRUCT
Dim hwnd As IntPtr '窗口句柄
Dim wFunc As Integer '执行的操作
Dim pFrom As String '原地点
Dim pTo As String '目标地点
Dim fFlags As Int32 '操作执行方式
Dim fAnyOperationsAborted As Integer '错误代码返回
Dim hNameMappings As Integer
Dim lpszProgressTitle As String
End Structure
Private Const FO_MOVE As Integer = &H1
Private Const FO_COPY As Integer = &H2
Private Const FO_DELETE As Integer = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FileOp As New SHFILEOPSTRUCT
Dim result As Integer
Try
With FileOp
.hwnd = Me.Handle
.wFunc = FO_COPY
.pFrom = "C:\*.*" & vbNullChar & vbNullChar
.pTo = "d:\123" & vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(FileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
End If
Else
If FileOp.fAnyOperationsAborted <> 0 Then
MsgBox("Operation Failed")
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
6 个解决方案
#1
87=ERROR_INVALID_PARAMETER
参数错误
参考一下http://vbnet.mvps.org/index.html?code/shell/shdirectorycopy.htm吧
参数错误
参考一下http://vbnet.mvps.org/index.html?code/shell/shdirectorycopy.htm吧
#2
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
用ByRef lpFileOp As SHFILEOPSTRUCT看看
用ByRef lpFileOp As SHFILEOPSTRUCT看看
#3
下列代码测试正确:
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Structure SHFILEOPSTRUCT
Dim hwnd As IntPtr '窗口句柄
Dim wFunc As Integer '执行的操作
Dim pFrom As String '原地点
Dim pTo As String '目标地点
Dim fFlags As Int32 '操作执行方式
Dim fAnyOperationsAborted As Integer '错误代码返回
Dim hNameMappings As Integer
Dim lpszProgressTitle As Integer 'String
End Structure
Private Const FO_MOVE As Integer = &H1
Private Const FO_COPY As Integer = &H2
Private Const FO_DELETE As Integer = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FileOp As New SHFILEOPSTRUCT
Dim result As Integer
Try
With FileOp
.hwnd = Me.Handle
.wFunc = FO_COPY
.pFrom = "c:\123\*.*" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.pTo = "d:\123" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(FileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
End If
Else
If FileOp.fAnyOperationsAborted <> 0 Then
MsgBox("Operation Failed")
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Structure SHFILEOPSTRUCT
Dim hwnd As IntPtr '窗口句柄
Dim wFunc As Integer '执行的操作
Dim pFrom As String '原地点
Dim pTo As String '目标地点
Dim fFlags As Int32 '操作执行方式
Dim fAnyOperationsAborted As Integer '错误代码返回
Dim hNameMappings As Integer
Dim lpszProgressTitle As Integer 'String
End Structure
Private Const FO_MOVE As Integer = &H1
Private Const FO_COPY As Integer = &H2
Private Const FO_DELETE As Integer = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FileOp As New SHFILEOPSTRUCT
Dim result As Integer
Try
With FileOp
.hwnd = Me.Handle
.wFunc = FO_COPY
.pFrom = "c:\123\*.*" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.pTo = "d:\123" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(FileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
End If
Else
If FileOp.fAnyOperationsAborted <> 0 Then
MsgBox("Operation Failed")
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
#4
在 .net 源代码里 copy 的,应该是好用的;
自己试验一下吧;
Friend NotInheritable Class NativeMethods
Friend Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
If (IntPtr.Size = 4) Then
Return NativeMethods.SHFileOperation32((lpFileOp))
End If
Dim shfileopstruct As New SHFILEOPSTRUCT64
shfileopstruct.hwnd = lpFileOp.hwnd
shfileopstruct.wFunc = lpFileOp.wFunc
shfileopstruct.pFrom = lpFileOp.pFrom
shfileopstruct.pTo = lpFileOp.pTo
shfileopstruct.fFlags = lpFileOp.fFlags
shfileopstruct.fAnyOperationsAborted = lpFileOp.fAnyOperationsAborted
shfileopstruct.hNameMappings = lpFileOp.hNameMappings
shfileopstruct.lpszProgressTitle = lpFileOp.lpszProgressTitle
Dim num2 As Integer = NativeMethods.SHFileOperation64((shfileopstruct))
lpFileOp.fAnyOperationsAborted = shfileopstruct.fAnyOperationsAborted
Return num2
End Function
<DllImport("shell32.dll", EntryPoint:="SHFileOperation", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SHFileOperation32(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
End Function
<DllImport("shell32.dll", EntryPoint:="SHFileOperation", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SHFileOperation64(ByRef lpFileOp As SHFILEOPSTRUCT64) As Integer
End Function
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure SHFILEOPSTRUCT64
Friend hwnd As IntPtr
Friend wFunc As UInt32
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pFrom As String
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pTo As String
Friend fFlags As UInt16
Friend fAnyOperationsAborted As Boolean
Friend hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> _
Friend lpszProgressTitle As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1)> _
Friend Structure SHFILEOPSTRUCT
Friend hwnd As IntPtr
Friend wFunc As UInt32
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pFrom As String
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pTo As String
Friend fFlags As UInt16
Friend fAnyOperationsAborted As Boolean
Friend hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> _
Friend lpszProgressTitle As String
End Structure
End Class
自己试验一下吧;
#5
//还有这个
Friend Enum SHFileOperationType As UInt32
' Fields
FO_COPY = 2
FO_DELETE = 3
FO_MOVE = 1
FO_RENAME = 4
End Enum
#6
转眼一年没登陆,登陆上来居然发现还有个帖子没结。
不知道说什么好了。这日子过得!连上csdn都奢侈了。
不知道说什么好了。这日子过得!连上csdn都奢侈了。
#1
87=ERROR_INVALID_PARAMETER
参数错误
参考一下http://vbnet.mvps.org/index.html?code/shell/shdirectorycopy.htm吧
参数错误
参考一下http://vbnet.mvps.org/index.html?code/shell/shdirectorycopy.htm吧
#2
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
用ByRef lpFileOp As SHFILEOPSTRUCT看看
用ByRef lpFileOp As SHFILEOPSTRUCT看看
#3
下列代码测试正确:
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Structure SHFILEOPSTRUCT
Dim hwnd As IntPtr '窗口句柄
Dim wFunc As Integer '执行的操作
Dim pFrom As String '原地点
Dim pTo As String '目标地点
Dim fFlags As Int32 '操作执行方式
Dim fAnyOperationsAborted As Integer '错误代码返回
Dim hNameMappings As Integer
Dim lpszProgressTitle As Integer 'String
End Structure
Private Const FO_MOVE As Integer = &H1
Private Const FO_COPY As Integer = &H2
Private Const FO_DELETE As Integer = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FileOp As New SHFILEOPSTRUCT
Dim result As Integer
Try
With FileOp
.hwnd = Me.Handle
.wFunc = FO_COPY
.pFrom = "c:\123\*.*" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.pTo = "d:\123" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(FileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
End If
Else
If FileOp.fAnyOperationsAborted <> 0 Then
MsgBox("Operation Failed")
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Structure SHFILEOPSTRUCT
Dim hwnd As IntPtr '窗口句柄
Dim wFunc As Integer '执行的操作
Dim pFrom As String '原地点
Dim pTo As String '目标地点
Dim fFlags As Int32 '操作执行方式
Dim fAnyOperationsAborted As Integer '错误代码返回
Dim hNameMappings As Integer
Dim lpszProgressTitle As Integer 'String
End Structure
Private Const FO_MOVE As Integer = &H1
Private Const FO_COPY As Integer = &H2
Private Const FO_DELETE As Integer = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FileOp As New SHFILEOPSTRUCT
Dim result As Integer
Try
With FileOp
.hwnd = Me.Handle
.wFunc = FO_COPY
.pFrom = "c:\123\*.*" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.pTo = "d:\123" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(FileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
End If
Else
If FileOp.fAnyOperationsAborted <> 0 Then
MsgBox("Operation Failed")
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
#4
在 .net 源代码里 copy 的,应该是好用的;
自己试验一下吧;
Friend NotInheritable Class NativeMethods
Friend Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
If (IntPtr.Size = 4) Then
Return NativeMethods.SHFileOperation32((lpFileOp))
End If
Dim shfileopstruct As New SHFILEOPSTRUCT64
shfileopstruct.hwnd = lpFileOp.hwnd
shfileopstruct.wFunc = lpFileOp.wFunc
shfileopstruct.pFrom = lpFileOp.pFrom
shfileopstruct.pTo = lpFileOp.pTo
shfileopstruct.fFlags = lpFileOp.fFlags
shfileopstruct.fAnyOperationsAborted = lpFileOp.fAnyOperationsAborted
shfileopstruct.hNameMappings = lpFileOp.hNameMappings
shfileopstruct.lpszProgressTitle = lpFileOp.lpszProgressTitle
Dim num2 As Integer = NativeMethods.SHFileOperation64((shfileopstruct))
lpFileOp.fAnyOperationsAborted = shfileopstruct.fAnyOperationsAborted
Return num2
End Function
<DllImport("shell32.dll", EntryPoint:="SHFileOperation", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SHFileOperation32(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
End Function
<DllImport("shell32.dll", EntryPoint:="SHFileOperation", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SHFileOperation64(ByRef lpFileOp As SHFILEOPSTRUCT64) As Integer
End Function
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure SHFILEOPSTRUCT64
Friend hwnd As IntPtr
Friend wFunc As UInt32
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pFrom As String
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pTo As String
Friend fFlags As UInt16
Friend fAnyOperationsAborted As Boolean
Friend hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> _
Friend lpszProgressTitle As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1)> _
Friend Structure SHFILEOPSTRUCT
Friend hwnd As IntPtr
Friend wFunc As UInt32
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pFrom As String
<MarshalAs(UnmanagedType.LPTStr)> _
Friend pTo As String
Friend fFlags As UInt16
Friend fAnyOperationsAborted As Boolean
Friend hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> _
Friend lpszProgressTitle As String
End Structure
End Class
自己试验一下吧;
#5
//还有这个
Friend Enum SHFileOperationType As UInt32
' Fields
FO_COPY = 2
FO_DELETE = 3
FO_MOVE = 1
FO_RENAME = 4
End Enum
#6
转眼一年没登陆,登陆上来居然发现还有个帖子没结。
不知道说什么好了。这日子过得!连上csdn都奢侈了。
不知道说什么好了。这日子过得!连上csdn都奢侈了。