all groups > dotnet interop > january 2007 >
You're in the

dotnet interop

group:

Anyone gotten SHGetFolderLocation to work?


Anyone gotten SHGetFolderLocation to work? Ian Boyd
1/13/2007 9:31:51 PM
dotnet interop: 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)
}
}

Re: Anyone gotten SHGetFolderLocation to work? Ian Boyd
1/14/2007 9:30:39 AM

[quoted text, click to view]



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)

Re: Anyone gotten SHGetFolderLocation to work? Mattias Sjögren
1/14/2007 2:31:29 PM
Ian,

[quoted text, click to view]

Try using CSIDL_PERSONAL (0x5) instead of CSIDL_MYDOCUMENTS.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button