Dim hr As Long
Dim bReaded As Long
Dim hFile As Long
Dim dwFileSize As Long
Dim dwBytesRead As Long
Dim hGlobal As Long
Dim pvData As Long
Dim sa As SECURITY_ATTRIBUTES
With sa
.bInheritHandle = 0
.lpSecurityDescriptor = 0
.nLength = 0
End With
On Error Resume Next
hFile = CreateFile(bstrFileName, GENERIC_READ, FILE_SHARE_READ, sa, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, 0)
If (hFile > 0) Then
dwFileSize = GetFileSize(hFile, 0)
If (dwFileSize > -1) Then
hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize)
End If
End If
If (hGlobal > 0) Then
pvData = GlobalLock(hGlobal)
If (pvData > 0) Then
bReaded = ReadFile(hFile, ByVal pvData, dwFileSize, dwBytesRead, 0&)
If (bReaded <> 0) Then
Set pStream = CreateStreamOnHGlobal(hGlobal, True)
pStream.Seek 0, 0
End If
GlobalUnlock (hGlobal)
End If
If (hr <> S_OK) Then
GlobalFree (hGlobal)
Set pStream = Nothing
End If
End If
If (hFile > 0) Then
CloseHandle (hFile)
End If
End Sub
上一页 [1] [2]
责任编辑:小草