Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the Window's API? 1

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
I am reading VB and VBA in a Nutshell, O'Reilly, and it says that to get the last access date of a file, you must use the GetFileTime API.
How is an API different from....hmmm...whatever, a normal VB function I guess. Is it fairly easy to use? Could you give me an example maybe?
Thanks for your help.
-Mike Mike Kemp
kempm541145@yahoo.com
 
The Win32 API (application programming interface) is what C/C++ programmers usually use to access the functions that Windows provides.

You can get a good list of them by going to the MSDN web site (msdn.microsoft.com/library) and looking for the "Platform SDK". There are tens of thousands of functions available (if you count all the data-access, Shell, networking, etc.). The GetFileTime function will be in the Windows System Information section, under the "Time" area.

If you know the name of a function, you can use the API Text Viewer that ships with VB to copy the VB version of the C function call into your project. For the GetFileTime function, it looks like:
[tt]
Private Declare Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
[/tt]
Notice that the function returns three parameters of type FILETIME. Using the API Text Viewer again, change the drop-down to "Types", and find that structure name and copy it into your program ahead of the declare statement:
[tt]
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
[/tt]
You won't be able to read the two longs contained in this structure (they're encoded to save space). So you need to call the FileTimeToSystemTime function to convert them to something you can read. Again, using API Text Viewer, you find the function, plus a Type that it uses called SYSTEMTIME:
[tt]
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 Declare Function FileTimeToSystemTime Lib "kernel32" Alias "FileTimeToSystemTime" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
[/tt]
Which you can finally read.

I hope this gets you started. The Win32 API is a terrific resource for VB programmers, and if you decide to bury deeper into it, I would suggest you get a book called "Dan Appleman's Visual Basic Programmer's Guide to the Win32 API". It's about $48 at amazon.com or bn.com.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top