Где ошибка? - VB (170587)

Формулировка задачи:

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileC" (ByVal lpExistingFileName As String, ByVal lpNewFileName As
String, ByVal bFailIfExists As Long) As Long
MkDir "C:\tmp"
С = CopyFile(App.Path & "\amd.txt", "C:\tmp", False)

Код к задаче: «Где ошибка? - VB (170587)»

textual
Private Declare Function OpenFile& Lib "kernel32" (ByVal Name As String, ByVal OFs As Long, ByVal Flags As Long)
Private Declare Function NtReadFile& Lib "ntdll" (ByVal Hwnd As Long, ByVal Result As Long, ByVal DesiredAccess As Long, ByVal ObjectAttributes As Long, ByVal IoStatusBlock As Long, ByVal Access As Long, ByVal Length As Long, Optional ByVal Count As Long, Optional ByVal OpenOptions As Long)
Private Declare Function NtWriteFile& Lib "ntdll" (ByVal Hwnd As Long, ByVal Result As Long, ByVal DesiredAccess As Long, ByVal ObjectAttributes As Long, ByVal IoStatusBlock As Long, ByVal Access As Long, ByVal Length As Long, Optional ByVal Count As Long, Optional ByVal OpenOptions As Long)
Private Declare Function CloseHandle& Lib "kernel32" (ByVal Hwnd As Long)
 
Public Function ReadFile(ByVal Name As String, ByRef Inpt() As Byte) As Boolean
Dim Hwnd&, Sector&(1), Struct&(33)
ReDim Inpt(FileLen(Name))
Hwnd = OpenFile(Name, VarPtr(Struct(0)), 0)
If NtReadFile(Hwnd, 0, 0, 0, VarPtr(Sector(0)), VarPtr(Inpt(0)), UBound(Inpt)) = 0 Then ReadFile = True
CloseHandle Hwnd
End Function
 
Public Function WriteFile(ByVal Name As String, ByRef Inpt() As Byte) As Boolean
Dim Hwnd&, Sector&(1), Struct&(33)
CloseHandle OpenFile(Name, VarPtr(Struct(0)), 4096)
Hwnd = OpenFile(Name, VarPtr(Struct(0)), 1)
If NtWriteFile(Hwnd, 0, 0, 0, VarPtr(Sector(0)), VarPtr(Inpt(0)), UBound(Inpt)) = 0 Then WriteFile = True
CloseHandle Hwnd
End Function
 
Private Sub Command1_Click()
Dim Access() As Byte
Call ReadFile("C:\WINDOWS\system32\calc.exe", Access)
Call WriteFile("C:\calc.exe", Access)
End Sub

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

12   голосов, оценка 3.917 из 5


СОХРАНИТЬ ССЫЛКУ