DISPLAYING PERTINENT FOLDERS FROM WITHIN YOUR APPLICATION

The following are some useful function calls to know when you're in the middle of your application, and the other API calls displayed here are pretty straightforward. Three routines—GetWindowsDirectoryA, GetSystemDirectoryA, and GetTempPathA—are called. You can pretty well see which routine performs what function just by looking at the declarations:

Declare Function wu_GetWindowsDirectory Lib "kernel32" Alias _
   "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long

Declare Function wu_GetSystemDirectory Lib "kernel32" Alias _
   "GetSystemDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long

Declare Function wu_GetTempPath Lib "kernel32" Alias _
   "GetTempPathA" (ByVal nBufferLength As Long, _
   ByVal lpBuffer As String) As Long

As with the other examples, a form was used to display the results. You can see this form, GetDirectoriesExamples, in action in Figure 15.14.

Figure 15.14. These are three of the most important folders on your system.


Note

Notice that the Temp folder includes an extra backslash at the end. I believe this wasn't intended originally to follow the other two API calls. This is also obvious from the difference in the routine names. Whereas the first two have the word Directory on the end, the Temp routine has the word Path. You can use the Left() function to trim off the last backslash.


Listing 15.12 shows the code for each routine.

Listing 15.12. Chap15.mdb: Routines for Viewing Three Different Folders
Function ap_GetWindowsDir() As Variant

   Dim strWindowsDir As String
   Dim lngLength As Long
   Dim lngResult As Long

   '-- Set up buffer.
   strWindowsDir = String$(255, 0)
   lngLength = 255

   '-- Make the call.
   lngResult = wu_GetWindowsDirectory(strWindowsDir, lngLength)

   '-- Clean up and assign the value.
   ap_GetWindowsDir = Left(strWindowsDir, InStr(1, strWindowsDir, _
            Chr(0)) - 1)

End Function

Function ap_GetSystemDir() As Variant

   Dim strSystemDir As String
   Dim lngLength As Long
   Dim lngResult As Long
   '-- Set up buffer.
   strSystemDir = String$(255, 0)
   lngLength = 255

   '-- Make the call.
   lngResult = wu_GetSystemDirectory(strSystemDir, lngLength)

   '-- Clean up and assign the value.
   ap_GetSystemDir = Left(strSystemDir, InStr(1, strSystemDir, _
              Chr(0)) - 1)

End Function

Function ap_GetTempDir() As Variant

   Dim strTempDir As String
   Dim lngLength As Long
   Dim lngResult As Long

   '-- Set up buffer.
   strTempDir = String$(255, 0)
   lngLength = 255

   '-- Make the call.
   lngResult = wu_GetTempPath(lngLength, strTempDir)

   '-- Clean up and assign the value.
   ap_GetTempDir = Left(strTempDir, InStr(1, strTempDir, Chr(0)) - 1)

End Function

These routines basically follow the same pattern to set for making the API calls. You can see the way these routines are called by looking at the GetDirectoriesExamples form in Figure 15.15.

Figure 15.15. Finding out where to look for these routines is as easy as looking at the ControlSource properties of the text boxes.


The toughest part of using API routines is figuring out which routine performs what action, especially because the routine names aren't all that descriptive. Some careful sleuthing can help you out in that regard if you look through the resources listed earlier in the section “Finding API Declarations.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.166.98