VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find the Application Data Folder in Windows XP

by RRKSS (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

This article uses the SHGetFolderPath API to find the Application Data Folder In "C:\Documents and Settings\UserName\Application Data\" so you can save program data files and allow limited users in windows xp to use you program easier.

Rate Find the Application Data Folder in Windows XP

Since the SHGetFolderPath API is not in the api viewer here are the declarations you need.


Declare Function SHGetFolderPath Lib "shell32.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal lpszPath As String) As Long

Public Const CSIDL_APPDATA = &H1A

Public Const SHGFP_TYPE_CURRENT = 0

Public Const SHGFP_TYPE_DEFAULT = 1

Public DataFolder as String


Add a module to your project and copy and paste those declarations into the module. Now create a function called GetDataFolder and paste this code into it.


Public Function GetDataFolder()

 On Error Goto GenericFolder

 Dim ReturnVal as long

 Dim PathName as long

 pathname = Space(260)

 retval = SHGetFolderPath(Form1.hWnd, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, pathname)
 pathname = Left(pathname, InStr(pathname, vbNullChar) - 1)

 DataFolder = PathName

 exit function

GenericFolder:

 'Since Windows XP\2000 is not installed we don't have this api so just use the App.path

 if err.number = 453 then

  datafolder = app.path

 end if

end function


With that code you should be able to make your programs more XP compatible and still be able to run it on windows 9x. Please leave your comments and vote.

Download this snippet    Add to My Saved Code

Find the Application Data Folder in Windows XP Comments

No comments have been posted about Find the Application Data Folder in Windows XP. Why not be the first to post a comment about Find the Application Data Folder in Windows XP.

Post your comment

Subject:
Message:
0/1000 characters