GetSaveFileName() 不返回 XP 上 CD 刻录暂存区的路径 [英] GetSaveFileName() not returning path of CD burning staging area on XP

查看:26
本文介绍了GetSaveFileName() 不返回 XP 上 CD 刻录暂存区的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,可以将文件保存到用户指定的位置.我正在使用 GetSaveFileName() 来显示另存为对话框.然后我使用它返回的路径将文件写出到该位置.我注意到当用户在 XP 机器上选择 CD-RW 驱动器时它不起作用.同样的过程在 Vista 和 Windows 7 上也能正常工作.我做了以下观察:

I have a feature where I save a file to a location that user specifies. I'm using GetSaveFileName() to show the Save As dialog. I then use the path that it returns to write out the file to that location. I've noticed that it does not work when the user chooses the CD-RW drive on an XP machine. This same process works correctly on Vista and Windows 7. I've made the following observations:

  1. GetSaveFileName() 返回的路径返回的是在 Win7/Vista 上选择 CD 刻录机根文件夹(在我的情况下为 F:)时临时暂存区的路径.
  2. 在 XP 上,选择 CD 刻录机根文件夹只会返回 F:\ 作为路径.但是,如果我使用另存为"对话框创建子文件夹并将文件保存在此文件夹中(例如 F:\folder),则路径是临时文件夹的路径.
  3. 在 XP 中使用记事本等其他应用程序将正确重定向到 F:\ 的临时文件夹.

所以只有在XP上保存到CD刻录机的根文件夹时才会出现问题.如何在 XP 中实现与记事本相同的功能,并将另存为重定向到临时文件夹,以便我有一个可以写入 CreateFile() 的路径?

So the problem only exists when saving to the root folder of the CD burner on XP. How can I achieve the same functionality as Notepad in XP and have Save As redirect to the temp folder so I have have a path I can write to for CreateFile()?

推荐答案

我认为您返回某些路径的 CD 暂存区的事实是 IShellFolder::GetDisplayNameOf 方式的副产品" 功能有效.我发现对于 CD 刻录机,存在于暂存区的文件或文件夹的 PIDL 将转换为引用暂存区的字符串.CD 上存在的文件或文件夹的 PIDL(无论它是否也存在于暂存区)将转换为引用 CD 的字符串.因为根文件夹(根据定义)存在于 CD 上,所以它是您作为字符串返回的 CD 路径.

I think the fact that you get back the CD staging area for some paths is a "by-product" of the way the IShellFolder::GetDisplayNameOf function works. I've found that for CD burners, a PIDL for a file or folder that only exists in the staging area, will convert to a string referencing the staging area. A PIDL for a file or folder that exists on the CD (whether or not it exists in the staging area as well) will convert to a string referencing the CD. Because the root folder (by definition) exists on the CD, it's the CD path you get back as a string.

我建议您自己处理.您可以使用 ICDBurn::GetRecorderDriveLetter 函数来获取刻录机的驱动器号 - 然后与您从 GetSaveFileName() 返回的字符串进行比较是微不足道的.如果您确实找到了 CD 刻录机上的路径,则可以使用 SHGetFolderLocationCSIDL_CDBURN_AREA 来获取暂存区的路径 - 那么只需更换驱动器即可带有暂存区路径的路径字符串开头的字母.

I would suggest handling this yourself. You can use the ICDBurn::GetRecorderDriveLetter function to get the recorder's drive letter - then it's trivial to compare against the string you get back from GetSaveFileName(). If you do get back a path on the CD burner, you can use SHGetFolderLocation with CSIDL_CDBURN_AREA to get the path of the staging area - then it's simply a matter of replacing the drive letter at the beginning of the path string with the path of the staging area.

这篇关于GetSaveFileName() 不返回 XP 上 CD 刻录暂存区的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆