二级VB实现的FileStream代码
来源:优易学  2011-8-31 23:41:22   【优易学:中国教育考试门户网】   资料下载   IT书店

 

 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] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训