Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Public Declare Function SHGetSpecialFolderLocation2 Lib "shell32.dll" Alias "SHGetSpecialFolderLocation" (ByVal hWndOwner As Long, ByVal nFolder As Integer, ppidl As ItemIDList) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongType SHItemID   'mkid
    cb As Long      'Size of the ID (including cb itself)
    abID As Byte   'The item ID (variable length)
End TypeType ItemIDList  'idl
    mkid As SHItemID
End TypePublic Type BROWSEINFO
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type'Public Const SW_NORMAL = 1Public Enum BROWSEFORFOLDERFLAGS
    BIF_BROWSEFORCOMPUTER = &H1000
    BIF_BROWSEFORPRINTER = &H2000
    BIF_BROWSEINCLUDEFILES = &H4000
    BIF_DONTGOBELOWDOMAIN = &H2
    BIF_EDITBOX = &H10
    BIF_RETURNFSANCESTORS = &H8
    BIF_RETURNONLYFSDIRS = &H1
    BIF_STATUSTEXT = &H4
    BIF_USENEWUI = &H40
    BIF_VALIDATE = &H20
End EnumPublic Enum SHELLFOLDERS            ' Shell Folder Path Constants...
    CSIDL_DESKTOP = &H0&            ' ..\WinNT\profiles\username\Desktop
    CSIDL_PROGRAMS = &H2&           ' ..\WinNT\profiles\username\Start Menu\Programs
    CSIDL_CONTROLS = &H3&           ' No Path
    CSIDL_PRINTERS = &H4&           ' No Path
    CSIDL_PERSONAL = &H5&           ' ..\WinNT\profiles\username\Personal
    CSIDL_FAVORITES = &H6&          ' ..\WinNT\profiles\username\Favorites
    CSIDL_STARTUP = &H7&            ' ..\WinNT\profiles\username\Start Menu\Programs\Startup
    CSIDL_RECENT = &H8&             ' ..\WinNT\profiles\username\Recent
    CSIDL_SENDTO = &H9&             ' ..\WinNT\profiles\username\SendTo
    CSIDL_BITBUCKET = &HA&          ' No Path
    CSIDL_STARTMENU = &HB&          ' ..\WinNT\profiles\username\Start Menu
    CSIDL_DESKTOPDIRECTORY = &H10&  ' ..\WinNT\profiles\username\Desktop
    CSIDL_DRIVES = &H11&            ' No Path
    CSIDL_NETWORK = &H12&           ' No Path
    CSIDL_NETHOOD = &H13&           ' ..\WinNT\profiles\username\NetHood
    CSIDL_FONTS = &H14&             ' ..\WinNT\fonts
    CSIDL_TEMPLATES = &H15&         ' ..\WinNT\ShellNew
    CSIDL_COMMON_STARTMENU = &H16&  ' ..\WinNT\profiles\All Users\Start Menu
    CSIDL_COMMON_PROGRAMS = &H17&   ' ..\WinNT\profiles\All Users\Start Menu\Programs
    CSIDL_COMMON_STARTUP = &H18&    ' ..\WinNT\profiles\All Users\Start Menu\Programs\Startup
    CSIDL_COMMON_DESKTOPDIRECTORY = &H19& '..\WinNT\profiles\All Users\Desktop
    CSIDL_APPDATA = &H1A&           ' ..\WinNT\profiles\username\Application Data
    CSIDL_PRINTHOOD = &H1B&         ' ..\WinNT\profiles\username\PrintHood
End Enum' 获取系统相关路径。
Public Function GetSystemFolderPath(ByVal hWnd As Long, ByVal ID As SHELLFOLDERS, sfPath As String) As Long
'---------------------------------------------------------------
    Dim rc As Long                                      ' 返回值
    Dim pidl As Long                                    ' Item ID List
    Dim cbPath As Long                                  ' 路径长度
    Dim szPath As String                                ' 保存路径的变量
'---------------------------------------------------------------
    szPath = String(MAX_PATH, vbNullChar)    rc = SHGetSpecialFolderLocation(hWnd, ID, pidl)     ' Get pidl for Id...
    If (rc = 0) Then                                    ' If success is 0
'    #If UNICODE Then
'        rc = SHGetPathFromIDList(ByVal pidl, StrPtr(szPath))  ' Get Path from Item Id List
'    #Else
        rc = SHGetPathFromIDList(ByVal pidl, szPath)          ' Get Path from Item Id List
'    #End If
        If (rc = 1) Then                                ' If success is 1
            szPath = Trim(szPath)                      ' Fix path string
            cbPath = Len(szPath)                        ' Get length of path
            
'            If (Asc(Right(szPath, 1)) = 0) Then cbPath = cbPath - 1 ' Adjust path length
'            If (cbPath > 0) Then sfPath = Left(szPath, cbPath) ' Adjust path string variable
            sfPath = Trim(RTrimNull(Trim(szPath)))
            GetSystemFolderPath = True                  ' Return success
        End If
        CoTaskMemFree pidl
    End If
'---------------------------------------------------------------
End Function实验:
a$=""
? GetSystemFolderPath(0,6,a$)
-1
? a$
C:\Documents and Settings\汪杰.MIDNIGHT-FRANK\Favorites好了,拿分来!^_^

解决方案 »

  1.   

    哎呀!漏了一个函数声明!
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)好了,拿分来!^_^ 
      

  2.   

    to DevilXelloss:
    试过你这种方法,只能获得收藏夹目录,不能获得Links(链接)目录阿。to xxfeiyu:
    链接在收藏夹中应该没有的
      

  3.   

    不好意思写错了。
    to xxfeiyu:
    链接在注册表中应该没有的 
      

  4.   

    哎呀!我真糊涂!又忘了告诉你:HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar 下面有一个“LinksFolderName”,就是你要的东东。把收藏夹目录后面加上这个键的键值就可以了。好了,拿分来!^_^ 
      

  5.   

    to DevilXelloss(傑洛仕)
    呵呵,看来你挺猴急的:Pherro,可以给我一点分吗?我快穷死了~~
      

  6.   

    ...
    我还是比较喜欢用API解决....
      

  7.   

    呵呵~~DevilXelloss(傑洛仕) ,看来你白来了,人家就是不肯给分……