Part IV: Professional Database Development
954
The return value is the length of the returned string. Like GetWindowsDirectory, if the buffer
isn’t long enough, the return value is the length required to hold the temp path. If the function
fails, the return value is zero.
The wrapper for GetTempPathA properly interprets the return values when the API function is
called.
Function GetTempDir() As String
Dim Buffer As String * 255
Dim BufferSize As Long
Dim RetVal As Long
BufferSize = Len(Buffer)
RetVal = apiGetTempPath(BufferSize, Buffer)
If RetVal > 0 Then
GetTempDir = Left$(Buffer, RetVal)
Else
GetTempDir = vbNullString
End If
End Function
GetVersionExA
GetVersionEx returns the version number of the Windows installation on the user’s computer.
Declare Function apiGetVersion _
Lib “Kernel32” _
Alias “GetVersionExA”( _
ByRef osVer As OSVERSIONINFO) As Long
Notice that the GetVersionExA API function uses a data structure named OSVERSIONINFO as
one of its arguments. Notice that OSVERSIONINFO is passed by reference, which means that the
API function changes the contents of the data structure. GetVersionExA returns much of its data
by setting the members of OSVERSIONINFO to the values returned by Windows. Here’s the defi-
nition of OSVERSIONINFO:
Private Type OSVERSIONINFO
dwVersionInfo As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwplatformID As Long
szVersion As String * 128
End Type
The OSVERSIONINFO can be interpreted like this: dwVersionInfo is the length, in bytes, of the
data structure. dwMajorVersion is 6 for Windows Vista and Windows 7. The build number is a
value that is used mostly by Microsoft internally.