ShSetFolderPath 适用于 win7,不适用于 XP
我正在尝试在 C# 中使用 ShSetFolderPath 函数。我在 Win7 上工作,我已经设法使用 ShSetKnownFolderPath 并且它工作正常。
由于此功能在WinXP中不可用,因此我尝试调用ShSetFolderPath。因为我对调用不熟悉,所以我做了一些搜索并在一些法国论坛上找到了一些东西。我不会说法语,但这个声明是有道理的(如 MSDN 库中的函数文档):
[DllImport( "Shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "#232" ) ]
private static extern int SHSetFolderPath( int csidl, IntPtr hToken, uint flags, string path );
我这样称呼它:
private static int CSIDL_DESKTOP = 0x0000;
公共静态无效SetDesktopPath(字符串路径)
{
int ret;
ret = SHSetFolderPath(CSIDL_DESKTOP, IntPtr.Zero, 0, 路径);
如果(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?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的事情。
我再次查看了 CSIDL 列表。我意识到我正在尝试将一些“低级”参考(我猜)更改为桌面:
CSIDL_DESKTOP = 0x0000, // <桌面>
虽然我实际上只想更改文件夹位置,但我应该使用这个:
CSIDL_DESKTOPDIRECTORY = 0x0010, // <用户名>\Desktop
。这有效。
它解释了一切。我真丢脸。
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.
不,不是这样。错误代码转换为十六进制后为 0x80070057。 7表示Windows错误,57是错误代码87,ERROR_INVALID_PARAMETER,“参数不正确”。
有几个可能的原因。首先,入口点 #232 实际上并不是 SHSetFolderPath() 的入口点。您可能正在调用不同的函数,它不知道如何处理您传递的参数值。很难说,它是 XP 版本的 shell32.dll 上的未命名入口点。或者可能是 XP 对您更改桌面文件夹路径不满意。毫不奇怪,要真正实现这一点,它必须做很多事情,刷新所有 Explorer.exe 视图,重建桌面内容等等。
检查此线程以获取可能的帮助。
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.