Getting absolute path from relative in Vista seems to fail using Win32/Shell PathCombine()

岁酱吖の 提交于 2019-12-08 04:43:27

The documentation for PathCombine specifies that the second parameter, lpszDir, is "A pointer to a null-terminated string of maximum length MAX_PATH that contains the directory path." You appear to be passing the fully qualified name of a file inside the directory, instead of the fully qualified name of the directory. So, it removes three components: playlist.wpl, Playlists, and Music, and then appends the remainder.

You should be able to use PathRemoveFileSpec to remove the file part from your directory path.

When you combine your two strings, you get the following.

C:\Users\userX\Music\Playlists\playlist.wpl\..\..\..\Public\Music\Sample Music\Amanda.wma

Since each ".." will wipe out the preceding section, you end u[p with the following sequence:

C:\Users\userX\Music\Playlists\playlist.wpl\..\..\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Music\Playlists\..\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Music\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Public\Music\Sample Music\Amanda.wma

That's because "PathCombine()" is not bothered by whether any segments of your path are files or directories. It's just a relatively dumb way of matching special navigation characters (".." and ".") against real navigation segments to form a path without those special navigation characters.

It's just assuming that "playlist.wpl" is a directory name in your case. Strip that off (or add another ".." at the start of your relative path, a trick to avoid extraneous code for stripping of the filename section) and it should work okay.

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