Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2007

Tip: Looking for answers? Try searching our database.

Anyone gotten SHGetFolderLocation to work?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian Boyd - 14 Jan 2007 02:31 GMT
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)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.