« Canada is no longer a democracy | Mission accomplished » |
Some time back, I wrote about problems with the Windows ShellExecute/ShellExecuteEx functions if the filepath is longer than the predefined value of MAX_PATH.
The workaround I described was to use the short path name instead of the long path.
The Windows API has a function for that, GetShortPathName.
However, I recently found out that this function is broken, at least on Vista.
Apparently, the GetShortPathName function doesn't really get the short path by looking at the data on the disk. Instead, it seems to blindly truncate the full directory- and filenames, and appends ~1 at the end of each component. This works by accident on XP, but can result in problems on Vista.
To illustrate: Vista has directories C:\Program Files and C:\ProgramData. The short names of these directories are C:\PROGRA~1 and C:\PROGRA~2, respectively.
Using GetShortPathName on a path that starts with C:\ProgramData\..." results in "C:\PROGRA~1\...", though, as I found out during a debugging session.
This is of course completely unacceptable, and renders the GetShortPathName function unusable.
Typically, the MSDN documentation doesn't say anything about this...
And then MS wonders why they are hated by everybody...