• SHGetKnownFolderPath

    From Stefan Ungemach@21:1/5 to All on Thu Aug 24 08:13:40 2023
    Has anyone used the SHGetKnownFolderPath API function in VO yet? I've played around with it, but never get a result. Last attempt was:

    DEFINE FOLDERID_SkyDrive := "{A52BBA46-E9E1-435f-B3D9-28DAA648C0F6}"
    _dll function SHGetKnownFolderPath(pszGUID as psz,dwFlags as dword,hHandle as ptr,pOut ref psz) as logic pascal:Shell32.SHGetKnownFolderPath
    function getOneDriveDir() as string pascal
    local cRueck as string
    local pszPath as psz


    pszPath := memalloc( MAX_PATH )
    if SHGetKnownFolderPath( string2psz(FOLDERID_SkyDrive), 0, NULL, @pszpath )
    ? "success"
    cRueck := psz2string( pszPath )
    endif
    memfree( pszPath )
    return cRueck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ungemach@21:1/5 to Stefan Ungemach on Thu Aug 24 08:50:08 2023
    Stefan Ungemach schrieb am Donnerstag, 24. August 2023 um 17:13:42 UTC+2:
    Has anyone used the SHGetKnownFolderPath API function in VO yet? I've played around with it, but never get a result. Last attempt was:

    DEFINE FOLDERID_SkyDrive := "{A52BBA46-E9E1-435f-B3D9-28DAA648C0F6}"
    _dll function SHGetKnownFolderPath(pszGUID as psz,dwFlags as dword,hHandle as ptr,pOut ref psz) as logic pascal:Shell32.SHGetKnownFolderPath
    function getOneDriveDir() as string pascal
    local cRueck as string
    local pszPath as psz


    pszPath := memalloc( MAX_PATH )
    if SHGetKnownFolderPath( string2psz(FOLDERID_SkyDrive), 0, NULL, @pszpath )
    ? "success"
    cRueck := psz2string( pszPath )
    endif
    memfree( pszPath )
    return cRueck


    Update: This doesn't work either and even does not rech the "success" line:

    _dll function SHGetKnownFolderPath(pszGUID ref _WINGUID,dwFlags as dword,hHandle as ptr,pOut ref psz) as logic pascal:Shell32.SHGetKnownFolderPath#514
    function getOneDriveDir() as string pascal
    local cRueck as string
    local pszPath as psz
    local struGUID is _WINGUID

    if CreateGuidFromString(FOLDERID_SkyDrive, @struGUID)
    pszPath := memalloc( MAX_PATH )
    if SHGetKnownFolderPath( @struGUID, 0, NULL, @pszpath )
    ? "success"
    cRueck := psz2string( pszPath )
    ? len(cRueck)
    endif
    memfree( pszPath )
    endif
    return cRueck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jamal@21:1/5 to Stefan Ungemach on Fri Aug 25 23:52:41 2023
    Stefan,

    This was tricky to find the solution for as I never used before.
    I was getting a success but only the letter C was returned. I found out
    the pszPath returned as WCHAR type. VO has undocumented function to
    return the correct result using W2String() which uses Win32 WideCharToMultiByte() and VO's Mem2String() to return the full path
    correctly.

    Here is the full working code. Let me know how it goes.

    _dll function SHGetKnownFolderPath(pszGUID as _WINGUID, dwFlags as
    DWORD, hHandle as ptr, pOut ref ptr) as int
    pascal:Shell32.SHGetKnownFolderPath

    function GetKnownFolderPath(cGuidString as string) as string pascal
    local cFolderPath as string
    local pszPath as psz
    LOCAL pGuid as _WINGUID

    pGuid := MemAlloc( _sizeof( _WINGUID ) )

    CreateGuidFromString(cGuidString, pGuid)

    // ? Guid2String( pGuid )

    pszPath := MemAlloc( MAX_PATH )

    if SHGetKnownFolderPath( pGuid, 0, null_ptr, @pszPath ) = S_OK
    cFolderPath := W2String(pszPath)
    endif

    MemFree( pGuid )
    return cFolderPath


    FUNCTION Start()
    local a := {} as array
    local i as dword

    a := {ComputerFolder,Favorites, Documents,Pictures,Music,Videos,Downloads,Desktop,PublicDocuments,PublicPictures,PublicMusic,PublicVideos,PublicDownloads,UserProfile,Contacts,Links,PublicFolder,Programs}

    for i := 1 to ALen(a)
    ? GetKnownFolderPath(a[i])
    next

    WAIT

    RETURN nil

    // defines
    DEFINE ComputerFolder := "{0AC0837C-BBF8-452A-850D-79D08E667CA7}"
    DEFINE Favorites := "{1777F761-68AD-4D8A-87BD-30B759FA33DD}"
    DEFINE Documents := "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}"
    DEFINE Pictures := "{33E28130-4E1E-4676-835A-98395C3BC3BB}"
    DEFINE Music := "{4BD8D571-6D19-48D3-BE97-422220080E43}"
    DEFINE Videos := "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}"
    DEFINE Downloads := "{374DE290-123F-4565-9164-39C4925E467B}"
    DEFINE Desktop := "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"
    DEFINE PublicDocuments := "{ED4824AF-DCE4-45A8-81E2-FC7965083634}"
    DEFINE PublicPictures := "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}"
    DEFINE PublicMusic := "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}"
    DEFINE PublicVideos := "{2400183A-6185-49FB-A2D8-4A392A602BA3}"
    DEFINE PublicDownloads := "{3D644C9B-1FB8-4F30-9B45-F670235F79C0}"
    DEFINE UserProfile := "{5E6C858F-0E22-4760-9AFE-EA3317B67173}"
    DEFINE Contacts := "{56784854-C6CB-462B-8169-88E350ACB882}"
    DEFINE Links := "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}"
    DEFINE PublicFolder := "{DFDF76A2-C82A-4D63-906A-5644AC457385}"
    DEFINE Programs := "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}"



    Jamal





    On 8/24/2023 11:13 AM, Stefan Ungemach wrote:
    Has anyone used the SHGetKnownFolderPath API function in VO yet? I've played around with it, but never get a result. Last attempt was:

    DEFINE FOLDERID_SkyDrive := "{A52BBA46-E9E1-435f-B3D9-28DAA648C0F6}"
    _dll function SHGetKnownFolderPath(pszGUID as psz,dwFlags as dword,hHandle as ptr,pOut ref psz) as logic pascal:Shell32.SHGetKnownFolderPath
    function getOneDriveDir() as string pascal
    local cRueck as string
    local pszPath as psz


    pszPath := memalloc( MAX_PATH )
    if SHGetKnownFolderPath( string2psz(FOLDERID_SkyDrive), 0, NULL, @pszpath )
    ? "success"
    cRueck := psz2string( pszPath )
    endif
    memfree( pszPath )
    return cRueck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ungemach@21:1/5 to Jamal on Thu Aug 31 03:52:39 2023
    Jamal schrieb am Samstag, 26. August 2023 um 05:52:45 UTC+2:
    Stefan,

    This was tricky to find the solution for as I never used before.
    I was getting a success but only the letter C was returned. I found out
    the pszPath returned as WCHAR type. VO has undocumented function to
    return the correct result using W2String() which uses Win32 WideCharToMultiByte() and VO's Mem2String() to return the full path correctly.

    Here is the full working code. Let me know how it goes.


    Hi Jamal,

    thanks for pointing out W2String() to me. After a slight modification (ShGetKnownFolderPath returns false for some reason the following code now works for me:

    function GetKnownFolderPath(cGuidString as string) as string pascal
    local cFolderPath as string
    local pszPath as psz
    local struGUID is _WINGUID

    if CreateGuidFromString(cGuidString, @struGUID)
    pszPath := MemAlloc( MAX_PATH )
    SHGetKnownFolderPath( @struGUID, 0, null_ptr, @pszPath )
    cFolderPath := W2String(pszPath)
    memfree( pszPath )
    endif
    return cFolderPath

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)