home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap22 / hugecopy.bas < prev    next >
Encoding:
BASIC Source File  |  1995-09-24  |  1.8 KB  |  63 lines

  1. Attribute VB_Name = "Module1"
  2. ' Constants with OpenFile API call.
  3. Private Const OF_WRITE = &H1
  4. Private Const OF_READ = &H0
  5. Private Const OF_CREATE = &H1000
  6.  
  7. ' Structure filled in by OpenFile API call.
  8. Private Type OFSTRUCT
  9.         cBytes As Byte
  10.         fFixedDisk As Byte
  11.         nErrCode As Integer
  12.         Reserved1 As Integer
  13.         Reserved2 As Integer
  14.         szPathName(128) As Byte
  15. End Type
  16.  
  17. ' declarations for the API functions that this class uses.
  18. Private Declare Function OpenFile Lib "kernel32" _
  19.     (ByVal lpFileName As String, _
  20.      lpReOpenBuff As OFSTRUCT, _
  21.      ByVal wStyle As Long) As Long
  22.  
  23. Private Declare Function hread Lib "kernel32" Alias "_hread" _
  24.     (ByVal hFile As Long, lpBuffer As Any, ByVal lBytes As Long) As Long
  25.  
  26. Private Declare Function hwrite Lib "kernel32" Alias "_hwrite" _
  27.     (ByVal hFile As Long, ByVal lpBuffer As String, ByVal lBytes As Long) As Long
  28.  
  29. Private Declare Function lclose Lib "kernel32" Alias "_lclose" _
  30.     (ByVal hFile As Long) As Long
  31.  
  32. Private inpOFS As OFSTRUCT
  33. Private outOFS As OFSTRUCT
  34. Private myBuf As String
  35. Private size As Long
  36.  
  37. Public Sub firstCopy(inp As String, out As String)
  38.     Dim hInp As Long
  39.     Dim hOut As Long
  40.  
  41.     size = FileLen(inp)
  42.     myBuf = String(size, "*")
  43.     hInp = OpenFile(inp, inpOFS, OF_READ)
  44.     hOut = OpenFile(out, outOFS, OF_CREATE Or OF_WRITE)
  45.     If (hInp <> -1 And hOut <> -1) Then
  46.         hread hInp, ByVal myBuf, size
  47.         hwrite hOut, ByVal myBuf, size
  48.     End If
  49.     lclose hOut
  50.     lclose hInp
  51. End Sub
  52.  
  53. Public Sub additionalCopy(out As String)
  54.     Dim hOut As Long
  55.  
  56.     hOut = OpenFile(out, outOFS, OF_CREATE Or OF_WRITE)
  57.     If (hOut <> -1) Then
  58.         hwrite hOut, ByVal myBuf, size
  59.     End If
  60.     lclose hOut
  61. End Sub
  62.  
  63.