Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: el_chente23 en 5 Agosto 2005, 21:51 pm



Título: Funcion API
Publicado por: el_chente23 en 5 Agosto 2005, 21:51 pm
Tengo un problema con una funcion API es GetFileInformationByHandle, la cual usa una estructura como parametro que se llama BY_HANDLE_FILE_INFORMATION, este estructura tiene la informacion de un archivo en el disco, el problema es que cuando quiero acceder a alguna propiedad de la estructura en especial a ftCreationTime, me dice que no coinciden los tipos.
¿Como Puedo acceder a esa informacion?

Saludos


Título: Re: Funcion API
Publicado por: goodbye en 6 Agosto 2005, 03:35 am
Ejemplo de GetFileInformationByHandle

Código:
Private Const OPEN_EXISTING = 3

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Type BY_HANDLE_FILE_INFORMATION
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    dwVolumeSerialNumber As Long
    nFileSizeHigh As Long
    nFileSizeLow As Long
    nNumberOfLinks As Long
    nFileIndexHigh As Long
    nFileIndexLow As Long
End Type

Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, 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 Sub Form_Load()
    Dim hFile As Long, FileInfo As BY_HANDLE_FILE_INFORMATION
    'create a handle to the file 'c:\autoexec.bat'
    hFile = CreateFile("c:\autoexec.bat", 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal 0&)
    'retrieve the file information
    GetFileInformationByHandle hFile, FileInfo
    'close the handle
    CloseHandle hFile
    'show the result
    MsgBox "File size: " + CStr(FileInfo.nFileSizeLow), vbInformation
End Sub


Título: Re: Funcion API
Publicado por: goodbye en 6 Agosto 2005, 05:25 am
Citar
el problema es que cuando quiero acceder a alguna propiedad de la estructura en especial a ftCreationTime, me dice que no coinciden los tipos.

Resuelto tu problema

Código:
Private Const OPEN_EXISTING = 3

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer
  wDay As Integer
  wHour As Integer
  wMinute As Integer
  wSecond As Integer
  wMilliseconds As Integer
End Type

Private Type BY_HANDLE_FILE_INFORMATION
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    dwVolumeSerialNumber As Long
    nFileSizeHigh As Long
    nFileSizeLow As Long
    nNumberOfLinks As Long
    nFileIndexHigh As Long
    nFileIndexLow As Long
End Type

Private Declare Function GetFileInformationByHandle Lib "kernel32" _
(ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long

Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As _
  FILETIME, lpLocalFileTime As FILETIME) As Long

Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As _
  FILETIME, lpSystemTime As SYSTEMTIME) As Long
 
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, 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 Sub Form_Load()
    Dim hFile As Long, FileInfo As BY_HANDLE_FILE_INFORMATION
    Dim CTime As FILETIME, STime As SYSTEMTIME

    hFile = CreateFile("c:\autoexec.bat", 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal 0&)

   If hFile = -1 Then
    MsgBox "Archivo no encontrado", vbOKOnly + vbInformation
    Exit Sub
   End If

    GetFileInformationByHandle hFile, FileInfo

    FileTimeToLocalFileTime FileInfo.ftCreationTime, CTime
   
    FileTimeToSystemTime CTime, STime
   
   MsgBox STime.wDay & "." & STime.wMonth & "." & _
  STime.wYear & vbCrLf & STime.wHour & ":" & STime.wMinute & ":" & _
  STime.wSecond, vbInformation,"File Creation Time"
   
  CloseHandle hFile
   
End Sub


Saludos  ;D


Título: Re: Funcion API
Publicado por: el_chente23 en 6 Agosto 2005, 21:16 pm
Excelente, funciona a la perfeccion, ya vi porque no me salia, Gracias.

Saludos  ;D