CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Using api

  1. #1
    Join Date
    Apr 2001
    Posts
    36

    Using api

    Trying to figure out how to use a specific function in kernel32.ll Here's the function

    Declare Function FileTimeToLocalFileTime& Lib "kernel32" (lpFileTime as _
    FILETIME, lpLocalFileTime as FILETIME)




    I am using wininet.dll to download a file which works. Just trying to figure out how to convert a FILETIME to localtime so you can read the date the file was created or maybe I'm doing it the wrong way.

    I want to be able to ftp to a site and check for files that are over two weeks old.


  2. #2
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Using api

    This is an example from API Guide :

    'This program needs a Dialog box, named CDBox1
    ' (to add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    ' and select Microsoft Common Dialog control)
    private Type FILETIME
    dwLowDateTime as Long
    dwHighDateTime as Long
    End Type
    private Type SHFILEOPSTRUCT
    hWnd as Long
    wFunc as Long
    pFrom as string
    pTo as string
    fFlags as Integer
    fAborted as Boolean
    hNameMaps as Long
    sProgress as string
    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 Const GENERIC_WRITE = &H40000000
    private Const OPEN_EXISTING = 3
    private Const FILE_SHARE_READ = &H1
    private Const FILE_SHARE_WRITE = &H2
    private Const FO_DELETE = &H3
    private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (byval lpExistingFileName as string, byval lpNewFileName as string, byval bFailIfExists as Long) as Long
    private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (byval lpPathName as string, lpSecurityAttributes as Long) as Long
    private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (byval lpFileName as string) as Long
    private Declare Function GetFileSize Lib "kernel32" (byval hFile as Long, lpFileSizeHigh as Long) as Long
    private Declare Function GetFileTime Lib "kernel32" (byval hFile as Long, lpCreationTime as FILETIME, lpLastAccessTime as FILETIME, lpLastWriteTime as FILETIME) as Long
    private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (byval lpExistingFileName as string, byval lpNewFileName as string) as Long
    private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (byval lpFileName as string, byval dwDesiredAccess as Long, byval dwShareMode as Long, lpSecurityAttributes as Long, 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 Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp as SHFILEOPSTRUCT) as Long
    private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime as FILETIME, lpSystemTime as SYSTEMTIME) as Long
    private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime as FILETIME, lpLocalFileTime as FILETIME) as Long
    private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim lngHandle as Long, SHDirOp as SHFILEOPSTRUCT, lngLong as Long
    Dim Ft1 as FILETIME, Ft2 as FILETIME, SysTime as SYSTEMTIME
    'set the dialog's title
    CDBox.DialogTitle = "Choose a file ..."
    'Raise an error when the user pressed cancel
    CDBox.CancelError = true
    'Show the 'Open File'-dialog
    CDBox.ShowOpen
    'Create a new directory
    CreateDirectory "C:\KPD-Team", byval &H0
    'Copy the selected file to our new directory
    CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0
    'Rename the file
    MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd"
    'Open the file
    lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, byval 0&, OPEN_EXISTING, 0, 0)
    'get the file's size
    MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes."
    'get the fil's time
    GetFileTime lngHandle, Ft1, Ft1, Ft2
    'Convert the file time to the local file time
    FileTimeToLocalFileTime Ft2, Ft1
    'Convert the file time to system file time
    FileTimeToSystemTime Ft1, SysTime
    MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" + LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear))
    'Close the file
    CloseHandle lngHandle
    'Delete the file
    DeleteFile "C:\KPD-Team\test.kpd"
    With SHDirOp
    .wFunc = FO_DELETE
    .pFrom = "C:\KPD-Team"
    End With
    'Delete the directory
    SHFileOperation SHDirOp
    End
    End Sub





    HTH
    Vlad


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured