开发者

ShSetFolderPath works on win7, doesn't on XP

开发者 https://www.devze.com 2022-12-24 16:41 出处:网络
I\'m trying to use ShSetFolderPath function in C#. I work on Win7, I\'ve managed to use ShSetKnownFolderPath and it works fine.

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 inv开发者_如何学Gooking, 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?


Funny thing.
I've taken another look at CSIDL list. And I've realized I was trying to change some "low-level" reference (i guess) to desktop:
CSIDL_DESKTOP = 0x0000, // <desktop>
While I actually wanted to change just folder location, and i should've use this:
CSIDL_DESKTOPDIRECTORY = 0x0010, // <user name>\Desktop.
And THIS works.

It explains everything. Shame on me.


Nah, that's not it. The error code, converted to hex, is 0x80070057. The 7 indicates a Windows error, 57 is error code 87, ERROR_INVALID_PARAMETER, "The parameter is incorrect".

A couple of possible reasons. First is that entry point #232 isn't actually the entry point for SHSetFolderPath(). You might be calling a different function, it wouldn't know what to do with the argument values you pass. Hard to say, it is an unnamed entry point on XP's version of shell32.dll. Or it could be that XP just isn't happy about you changing the desktop folder path. Not that surprising, there's a heckofalot it has to do to actually implement that, refreshing all Explorer.exe views, rebuilding the desktop contents and whatnot.

Check this thread for possible help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号