GetSaveFileName() not returning path of CD burning staging area on XP

北城余情 提交于 2019-12-11 06:01:48

问题


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. The path returned by GetSaveFileName() returns the path of the temporary staging area when choosing the CD burner root folder (F: in my case) on Win7/Vista.
  2. On XP, choosing the CD burner root folder just returns F:\ as the path. HOWEVER, if I create a sub folder using the Save As dialog and save the file in this folder (e.g. F:\folder), the path is that of the temporary folder.
  3. Using another application such as Notepad in XP will correctly redirect to the temp folder for F:\ .

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()?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/3118667/getsavefilename-not-returning-path-of-cd-burning-staging-area-on-xp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!