Re: CreateFile and MAX_PATH and UNICODE
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Wed, 15 Feb 2006 09:55:14 +0900
"sienaman" <sienaman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:991707DC-D931-458D-B108-78CDEA5DD867@xxxxxxxxxxxxxxxx
Seems like CreateFile does not support filename longer than 208 characters.
I've been having weird problems on occasion, and wonder if you might have found an explanation. I didn't try to look for magic numbers unrelated to MAX_PATH but that could be it.
In the SDK docs, it says that "In the ANSI version of this function, the name is limited to MAX_PATH characters.
Yup, the SDK docs do say that. I reported to Microsoft that this is a bug. The fact is that in the ANSI version of this function, the name is limited to MAX_PATH _bytes_ not characters (that is, unless 208 is a magic number as you seem to have discovered). Microsoft replied with an assertion that I had a misunderstanding and an assertion that in ANSI every character is a single byte. That made it pretty clear that Microsoft needs to provide more training to Microsoft employees, so I tried to escalate the issue in hopes (silly me) that Microsoft might understand and provide more training to Microsoft employees. Microsoft retorted that I live in Australia (false), and therefore I should pay a support fee to Microsoft Japan (which happens to be where I live) in hopes of getting Microsoft Japan's support staff to teach Microsoft to provide more training to Microsoft employees. So much for the idea of sending e-mail directly to Microsoft where MSDN pages solicit e-mail. Public postings do tend to get higher quality responses, on average.
To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path". As simple test of this would be to try and create a file with a 255 character name with either a DOS prompt
Wrong. Either the DOS prompt is going to call the ANSI version of the function instead of the Unicode version, or it's going to do something else that yields the same results as if it were calling the ANSI version.
or right clicking on the Desktop to create say a new text file.
I think that Windows Explorer calls Unicode APIs, but still, Windows Explorer is a program with its own limitation. You didn't write the code for Windows Explorer and you didn't put in a buffer allocation routine that could handle 32,767 wide characters. In order to get what Windows will let you get, you have to write your own program.
Both methods fail for filenames longer than 208 characters. Also, any attempt to create a file with a name longer than 208 characters using CreateFile fails (including the extension) fails.
Again I didn't notice 208 being a magic number but I've seen various unexpected behaviour on occasion.
.
- Follow-Ups:
- Re: CreateFile and MAX_PATH and UNICODE
- From: Alexander Grigoriev
- Re: CreateFile and MAX_PATH and UNICODE
- From: Norman Diamond
- Re: CreateFile and MAX_PATH and UNICODE
- Prev by Date: Re: File System Monitoring
- Next by Date: Re: Why Interactive Windows Service is considered a risk?
- Previous by thread: Re: CreateFile and MAX_PATH and UNICODE
- Next by thread: Re: CreateFile and MAX_PATH and UNICODE
- Index(es):
Relevant Pages
|