Why does GetTempPath always return short path names? Is there a way to return the long path name rather than subsequently converting the returned string with GetLongPathName?
GetTempPath
is most likely returning the value of the TMP
or TEMP
environment variables, which (at least under Windows XP) are typically defined in terms of the short path name.
Windows appears to convert to the short path name from the HKEY_CURRENT_USER\Environment
registry key when initializing environment variables.
Rather than use GetTempPath, why not just get the value of the TEMP environment variable? That will be the long path already.
I do believe that this is done for compatibility reasons. In older Windows versions temp path was relatively short. In latest Windows this path is much longer. Many old application may use a buffer of fixed length (small length) for retrieving temp path. If you return long file name (which is relatively large now) - you'll broke this old programs, because their buffers just too small for it to fit. That's why GetTempPath returns short path name.