Funcion API

Iniciado por el_chente23, 5 Agosto 2005, 21:51 PM

0 Miembros y 1 Visitante están viendo este tema.

el_chente23

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

goodbye

#1
Ejemplo de GetFileInformationByHandle

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
Al lado de la dificultad está la facilidad.
Cambiad de placeres, pero no cambies de amigos.
Aceptar un favor de un amigo, es hacerle otro.

goodbye

#2
Citarel 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

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
Al lado de la dificultad está la facilidad.
Cambiad de placeres, pero no cambies de amigos.
Aceptar un favor de un amigo, es hacerle otro.

el_chente23

Excelente, funciona a la perfeccion, ya vi porque no me salia, Gracias.

Saludos  ;D