求助:我的代码一运行vb就出错,自动关闭。且有时候可以读一些小文件,一遇到大的就不行了

iamnotyou 2003-01-06 04:22:14
Option Explicit

Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2

Const OPEN_EXISTING = 3
Const OPEN_ALWAYS = 4

Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000

Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long

Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes(1) As Byte
Dim bB As Long, Ret As Long

Private Sub Form_Load()

hNewFile = CreateFile("c:\aa.exe", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_ALWAYS, 0, 0)

hOrgFile = CreateFile("c:\checknet.exe", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)

bB = GetFileSize(hOrgFile, vbNull)

ReadFile hOrgFile, bBytes(1), bB, Ret, ByVal 0&

If Ret <> bB Then MsgBox "Error reading file ..."

WriteFile hNewFile, bBytes(1), bB, Ret, ByVal 0&

If Ret <> bB Then MsgBox "Error writing file ..."


CloseHandle hOrgFile
CloseHandle hNewFile

End Sub


...全文
5 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
holydiablo 2003-01-06
用bBytes动态数组
dim bBytes() as byte

用的时候
redim bBytes(bB) as byte
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7452

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告