ShSetFolderPath works on win7, doesn't on XP

Posted by pipboy3k on Stack Overflow See other posts from Stack Overflow or by pipboy3k
Published on 2010-03-21T11:53:51Z Indexed on 2010/03/21 13:51 UTC
Read the original article Hit count: 386

Filed under:
|
|

Hey.
I'm trying to use ShSetFolderPath function in C#. I work on Win7, I've managed to use ShSetKnownFolderPath and it works fine.
Since this function is unavaible in WinXP, i tried to invoke ShSetFolderPath. Because i'm not familiar with invoking, I've done some searching and found something on some French forum. I don't speak French, but this declaration makes sense (as written in Remarks of function documentation in MSDN library):

[DllImport( "Shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "#232" ) ]
private static extern int SHSetFolderPath( int csidl, IntPtr hToken, uint flags, string path );

I call it like that:


private static int CSIDL_DESKTOP = 0x0000;

public static void SetDesktopPath(string path) { int ret; ret = SHSetFolderPath(CSIDL_DESKTOP, IntPtr.Zero, 0, path);
if (ret != 0) { Console.WriteLine(ret); Console.WriteLine(Marshal.GetExceptionForHR(ret)); } }


It works in Win7, but in XP function returns -2147024809, which means "Value does not fall within the expected range".
My guess is, it's something wrong with Dll importing. Any idea?

© Stack Overflow or respective owner

Related posts about c#

Related posts about pinvoke