求一个API函数openfile在VB6.0中运用的例子

我试了很多次 怎么就不能打开文件呢?
2025-01-02 18:54:35
推荐回答(1个)
回答1:

Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName As String * 128
End Type
Private Const OF_READWRITE = &H2
Private Const OF_CREATE = &H1000
Dim fs As OFSTRUCT
Dim hFile As Long

Private Sub Command1_Click()
Dim i As Long
Dim s As String
i = 0
s = "Hello World"
fs.cBytes = Len(fs)
hFile = OpenFile("c:\tt.txt", fs, OF_CREATE Or OF_READWRITE)
WriteFile hFile, ByVal s, Len(s), i, ByVal 0
CloseHandle hFile
End Sub