Has anyone been able to get SHGetFolderLocation to work? i see plenty of
posts about people having problems with it, and one fellow saying it is not
possible to use under .NET.
For me it returns 0x80070057 "The parameter is incorrect"
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
class TestApp
{
public static void Main()
{
Int32 nToken = 0x000c; //CSIDL.CSIDL_MYDOCUMENTS;
IntPtr pidl = IntPtr.Zero;
Int32 result;
result = SHGetFolderLocation(
IntPtr.Zero, //hWnd
nToken, CSIDL
IntPtr.Zero, //Access Token
0, //reserved
out pidl);
Console.
if (result < 0)
{
throw new Win32Exception(result);
}
}
[DllImport("shell32.dll", EntryPoint = "SHGetFolderLocation",
SetLastError = true,
CallingConvention = CallingConvention.StdCall)]
public static extern Int32 SHGetFolderLocation(
IntPtr hwndOwner, //hWnd
Int32 nFolder, //CSIDL of folder
IntPtr hToken, //Access token
UInt32 dwReserved, //Zero
out IntPtr pidl);
[FlagsAttribute]
public enum CSIDL
{
/// <summary>
/// Version 6.0. The virtual folder representing the My Documents
desktop item.
/// This should not be confused with CSIDL_PERSONAL, which
represents the file system folder that physically stores the documents.
/// </summary>
CSIDL_MYDOCUMENTS = (0x000c)
}
}
Mattias Sjögren - 14 Jan 2007 13:31 GMT
Ian,
>For me it returns 0x80070057 "The parameter is incorrect"
Try using CSIDL_PERSONAL (0x5) instead of CSIDL_MYDOCUMENTS.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Ian Boyd - 14 Jan 2007 14:30 GMT
> Ian,
>
>>For me it returns 0x80070057 "The parameter is incorrect"
>
> Try using CSIDL_PERSONAL (0x5) instead of CSIDL_MYDOCUMENTS.
From the PSDK:
"
CSIDL_MYDOCUMENTS (0x000c)
The virtual folder representing the My Documents desktop item.
CSIDL_PERSONAL (0x0005)
The virtual folder representing the My Documents desktop item. This is
equivalent to CSIDL_MYDOCUMENTS.
"
CSIDL_PERSONAL works while CSIDL_MYDOCUMENTS doesn't.
You gotta love Microsoft (in the stalk, kidnap, and kill sorta way)