Note: Needed to edit the title and question, as initially I thought the problem is with ::CreateFile[W] - but it turns out, the error only happens on XP when I use MFC's Cfile class.
I am slightly confused by the behaviour of CFile::Open(...) (on Win7/64bit) when I pass the filename file_with_invalid_chars:<?>.txt to this function to request creation of the file.
On my Windows XP box, the call fails.
开发者_如何学PythonOn my Win7/64 box, the call succeeds, creating a file named file_with_invalid_chars.
What's happening?
I'm guessing it's creating an alternate data stream. Seems odd that it would fail on XP, though. The documentation says that characters legal for a file name are also legal for a stream name, though I guess that doesn't necessarily mean the inverse is true. Maybe Windows 7 supports < and > in stream names and Windows XP doesn't.
It turns out that this is due to a bugfix(?) in shlwapi.dll -
MFC's CFile class does some internal processing on the filename, and happens to call the PathStripToRoot Function.
This function resides in Shlwapi.dll and Win7 is shipped with a newer version than Windows XP.
The Version in Windows XP apparently does not work correctly with file-paths containing ADS colon separated stream names.
Example:
- On XP
PathStripToRoot(L"C:\\temp\\file.txt:stream");yields the stringC:\temp\file.txt:which is incorrect and leads to an error return fromCFile::Open - On Win7, the same call yields the actual root
C:\.
加载中,请稍侯......
精彩评论