windows_programming_notes.nbk: Home | Index | Next Page: ShowWindow | Previous Page: SHBrowseForFolder


 SHGetFolderPath

Deprecated. Gets the path of a folder identified by a CSIDL value.

Note As of Windows Vista, this function is merely a wrapper for SHGetKnownFolderPath. The CSIDL value is translated to its associated KNOWNFOLDERID and then SHGetKnownFolderPath is called. New applications should use the known folder system rather than the older CSIDL system, which is supported only for backward compatibility.

Syntax

    HRESULT SHGetFolderPath(  
        HWND hwndOwner,
        int nFolder,
        HANDLE hToken,
        DWORD dwFlags,
        LPTSTR pszPath
    );

Parameters

SHGFP_TYPE_CURRENT Retrieve the folder's current path. SHGFP_TYPE_DEFAULT Retreive the folder's default path. pszPath

Returns S_OK if successful, or an error value otherwise, including the following.

S_FALSE SHGetFolderPathA only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function. E_FAIL SHGetFolderPathW only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function. E_INVALIDARG The CSIDL in nFolder is not valid.

Remarks

This function is a superset of SHGetSpecialFolderPath, included with earlier versions of the Shell. On systems that preceded those that include Shell32.dll version 5.0 (Microsoft Windows Millennium Edition (Windows Me) and Windows 2000), SHGetFolderPath was obtained through SHFolder.dll, distributed with Microsoft Internet Explorer 4.0 and later versions. SHFolder.dll always calls the current platform's version of this function. If that fails, it tries to simulate the appropriate behavior. SHFolder.dll continues to be included for backward compatibility, but the function is now implemented in Shell32.dll.

Note On older systems that require the redistributable SHFolder.dll, you must explicitly link to SHFolder.lib before you link to Shell32.lib.

Only some CSIDL values are supported, including the following:

Example

The following code example uses SHGetFolderPath to find or create a folder and then creates a file in it.

TCHAR szPath::&lb;MAX_PATH];

if(SUCCEEDED(SHGetFolderPath(NULL, 
                             CSIDL_PERSONAL|CSIDL_FLAG_CREATE, 
                             NULL, 
                             0, 
                             szPath))) 
{
    PathAppend(szPath, TEXT("New Doc.txt"));
    HANDLE hFile = CreateFile(szPath, ...);
}

Function Information


windows_programming_notes.nbk: Home | Index | Next Page: ShowWindow | Previous Page: SHBrowseForFolder


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time