winapiwindows-7vb6known-folders

How To Use the SHGetKnownFolderPath Function from Vb6


I am currently adding Windows 7 support to an existing Vb6 project and I have ran into a problem with locating special folder paths using SHGetFolderPath which is not supported on Windows versions starting with Vista. I know I should use SHGetKnownFolderPath but I cannot find a good example implementing using SHGetKnownFolderPath API call in VB6.


Solution

  • Easier to use the Shell object Late binding is advised because Microsoft haven't been careful about compatibility with this object.

    Const ssfCOMMONAPPDATA = &H23 
    Const ssfLOCALAPPDATA = &H1c
    Const ssfAPPDATA = &H1a
    Dim strAppData As String 
    
    strAppData = _ 
        CreateObject("Shell.Application").NameSpace(ssfAPPDATA).Self.Path