Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúOption Explicit
Private Type OVERLAPPED
ternal As Long
ternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As Long, ByVal dwDesiredAccess&, ByVal dwShareMode&, ByVal lpSecurityAttributes&, ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal hTemplateFile&) As Long
Public Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As OVERLAPPED) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject&) As Long
Public Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Public Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Public Const GENERIC_READ As Long = &H80000000
Public Const GENERIC_WRITE As Long = &H40000000
Public Const FILE_SHARE_READ As Long = &H1&
Public Const FILE_SHARE_WRITE As Long = &H2&
Public Const CREATE_NEW As Long = 1&
Public Const CREATE_ALWAYS As Long = 2&
Public Const OPEN_EXISTING As Long = 3&
Public Const OPEN_ALWAYS As Long = 4&
Public Const TRUNCATE_EXISTING As Long = 5&
Public Const FILE_BEGIN As Long = 0
Public Function OpenTextFile(FileName As String) As String
Dim FileSize As Long
Dim hFile As Long
Dim lOverLapped As OVERLAPPED
Dim nReadRetVal As Long
Dim TxtBytes() As Byte
Dim Ret As Long
Dim I As Integer
Dim Start As Long
hFile = CreateFile(StrPtr(FileName), GENERIC_READ, FILE_SHARE_READ, 0&, OPEN_EXISTING, 0&, 0&)
If hFile = -1 Then
MsgBox "Error abriendo el archivo", vbCritical, "Error"
Else
FileSize = GetFileSize(hFile, 0)
ReDim TxtBytes(FileSize) As Byte
Start = 0
Call SetFilePointer(hFile, Start, 0, FILE_BEGIN)
nReadRetVal = ReadFile(hFile, TxtBytes(0), UBound(TxtBytes), Ret, lOverLapped)
If nReadRetVal = 0 Then
MsgBox ("Error para leer el archivo")
Else
For I = LBound(TxtBytes) To UBound(TxtBytes)
OpenTextFile = OpenTextFile & Chr(TxtBytes(I))
Next
End If
End If
CloseHandle hFile
End Function
Private Sub Form_Load()
MsgBox OpenTextFile("c:\a.txt")
End Sub
Cita de: Chino Morenohttp://msdn.microsoft.com/es-es/library/y9341s4f(VS.80).aspx