News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Beware of GetSaveFileName and MAX_PATH

Started by jdoe, October 08, 2008, 05:01:32 AM

Previous topic - Next topic

jdoe


Hi,

You must know that you can't create a file in a path that is longer than MAX_PATH (260 characters) in the Windows Explorer but while I was playing with the GetSaveFileName API, I can select a file in a 262 characters path (excluding the null-char). I was aware that some API are not rigourous about MAX_PATH which is supposed to include the null-char but it's not always the case.
Even though I set the nMaxFile member of the OPENFILENAME to MAX_PATH it can writes 3 bytes passed the end of the buffer. This is why I always use a buffer of MAX_PATH+4 when the documentation says MAX_PATH.

The same can occur with SHBrowseForFolder where a folder path in the Windows Explorer can't be longer than 248 characters (including the null-char) but this API can go beyond.

So the the MAX_PATH+4 is a rule I follow. Someone else has seen something weird with MAX_PATH ?


jdoe


gwapo

In C++, we usually use PATH_MAX or FILENAME_MAX instead of MAX_PATH, because many of the wrapper functions uses these limits and hopefully got around with the problems you've mentioned (hopefully, because I'm not sure)  :toothy

-chris