首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • Lib "Shell32.dll" Alias "SHFileOperationA" 拷贝文件问题
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-18 17:20:57 楼主
    弄了这么段代码。可是执行总是出错。result 总是87。也查不到87代表什么意思。这么几行还出问题,无比郁闷。

    顺便借问有没有什么材料或者书籍对各种API及其使用的结构有详细解释?

    VB.NET code
    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
    50  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-19 09:18:591楼 得分:0
    87=ERROR_INVALID_PARAMETER
    参数错误
    参考一下http://vbnet.mvps.org/index.html?code/shell/shdirectorycopy.htm吧
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-19 10:17:182楼 得分:0
    Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer


    用ByRef lpFileOp As SHFILEOPSTRUCT看看
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zdbb
    • 等级:
    发表于:2008-06-19 14:03:323楼 得分:0
    下列代码测试正确:
      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
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-19 23:16:514楼 得分:0
    在 .net 源代码里 copy 的,应该是好用的;

    VB.NET code
    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


    自己试验一下吧;
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-19 23:20:355楼 得分:0
    VB.NET code
    //还有这个 Friend Enum SHFileOperationType As UInt32 ' Fields FO_COPY = 2 FO_DELETE = 3 FO_MOVE = 1 FO_RENAME = 4 End Enum
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved