| ■No69942 (鯖の味噌 さん) に返信 > 2014/02/13(Thu) 10:52:44 編集(投稿者) > > Private Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileW" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Integer) As Integer > > Sub Main() > > Dim Result As Integer = CopyFile("\\?\C:\A.txt", "\\?\C:\B.txt", 0) > > End Sub > > このコードを実行してもResult=0となりコピーできません。 > どこを間違えているのでしょうか? > > Windows7 64bit SP1 > VS Express 2013 for Desktop > を使用しています。
返答をくださいました皆様ありがとうございました。 以下のように記述し、コピー出来ました。
Private Declare Unicode Function CopyFile Lib "kernel32.dll" Alias "CopyFileW" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Integer) As Integer Sub Main() Dim Result As Integer = CopyFile("\\?\C:\CopyTemp\A.txt", "\\?\C:\CopyTemp\B.txt", 1) If Result = 0 Then Trace.WriteLine(New ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).ToString()) End If End Sub
MarshalAsは付けていませんが問題ないでしょうか? |