Method SHGetKnownFolderPath
SHGetKnownFolderPath(Guid, uint, nint, out nint)
Retrieves the full path of a known folder identified by its GUID.
public static extern int SHGetKnownFolderPath(Guid rfid, uint dwFlags, nint hToken, out nint ppszPath)
Parameters
rfidGuidThe GUID of the known folder. This identifies the folder whose path is being retrieved.
dwFlagsuintFlags that specify special retrieval options. Typically set to 0 for default behavior.
hTokennintAn access token that represents a particular user. If this parameter is Zero, the function uses the access token of the calling process.
ppszPathnintWhen the method returns, contains a pointer to the string that specifies the path of the known folder. The caller is responsible for freeing this memory using FreeCoTaskMem(nint).
Returns
- int
Returns 0 if the function succeeds; otherwise, returns an error code. For a list of possible error codes, see the Windows API documentation.
Remarks
This method is a P/Invoke declaration for the Windows API function
SHGetKnownFolderPath. It is used to retrieve the path of a known folder, such as the Documents or
Desktop folder. Ensure that the memory pointed to by ppszPath
is freed after use to
avoid memory leaks.