Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetSpecialFolder API
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00420012
Message ID:
00420113
Vues:
21
>>They will be in a minute. :-) I looked there first.
>
>I figured as much. Not that it's of any interest, but I'm not sure if you can get stuff like the Desktop folder and others that the WScript.Shell object can get. Those actually require two separate function calls.

Not common to all Win32 implementations:

BOOL SHGetSpecialFolderPath(
HWND hwndOwner,
LPTSTR lpszPath,
int nFolder,
BOOL fCreate
);


Parameters
hwndOwner
Handle to the owner window the client should specify if it displays a dialog box or message box.
lpszPath
Address of a character buffer that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
nFolder
A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.
fCreate
Indicates if the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.
Return Values
Returns TRUE if successful, or FALSE otherwise.

came in with IE4/Win98/v4.71 of Shell32.DLL

-and-
SHGetFolderPath
Takes the CSIDL of a folder and returns the pathname.


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

Parameters
hwndOwner
Handle to an owner window. This parameter is typically set to NULL. If it is not NULL, and a dial-up connection needs to be made to access the folder, a UI prompt will appear in this window.
nFolder
A CSIDL value that identifies the folder whose path is to be retrieved. Only real folders are valid. If a virtual folder is specified, this function will fail. You can force creation of a folder with SHGetFolderPath by combining the folder's CSIDL with CSIDL_FLAG_CREATE.
hToken
An access token that can be used to represent a particular user. For systems earlier than Microsoft® Windows® 2000, it should be set to NULL. For later systems, hToken is usually set to NULL. However, you may need to assign a value to hToken for those folders that can have multiple users but are treated as belonging to a single user. The most commonly used folder of this type is My Documents.

The caller is responsible for correct impersonation when hToken is non-NULL. It must have appropriate security privileges for the particular user, including TOKEN_QUERY and TOKEN_IMPERSONATE, and the user's registry hive must be currently mounted. See Access Control for further discussion of access control issues.

dwFlags
Flags to specify which path is to be returned. It is used for cases where the folder associated with a CSIDL may be moved or renamed by the user. Flag Description
SHGFP_TYPE_CURRENT Return the folder's current path.
SHGFP_TYPE_DEFAULT Return the folder's default path.

pszPath
Buffer of length [MAX_PATH] to receive the path. If an error occurs or S_FALSE is returned, this string will be empty.
Return Values
Value Description
S_OK Success.
S_FALSE The CSIDL in nFolder is valid, but the folder does not exist.
E_INVALIDARG The CSIDL in nFolder is not valid.


A standard OLE-defined error result may also be returned.

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

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

Remarks
This function is a superset of SHGetSpecialFolderPath, included with earlier versions of the shell. It is implemented in a redistributable DLL, SHFolder.dll, that also simulates many of the new shell folders on older platforms such as Windows 95, Windows 98, and Windows NT 4.0. This DLL always calls the current platform's version of this function. If that fails, it will try to simulate the appropriate behavior. Only some CSIDLs are supported, including:

CSIDL_ADMINTOOLS
CSIDL_COMMON_ADMINTOOLS
CSIDL_APPDATA
CSIDL_COMMON_APPDATA
CSIDL_COMMON_DOCUMENTS
CSIDL_COOKIES
CSIDL_FLAG_CREATE
CSIDL_HISTORY
CSIDL_INTERNET_CACHE
CSIDL_LOCAL_APPDATA
CSIDL_MYPICTURES
CSIDL_PERSONAL
CSIDL_PROGRAM_FILES
CSIDL_PROGRAM_FILES_COMMON
CSIDL_SYSTEM
CSIDL_WINDOWS
Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in shfolder.h.
Import Library: ShFolder.Lib.

NB: NT 4/Win95 systems need to have SHFOLDER.DLL added to the Windows search path, but does not require registration.

Check the MSDN Library entry on CSLIDs if you really wanna get JRandomFolder
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform