CFile::Open()文件打开失败
请问下,CFile::Open()这个方法的第一个参数,如果文件的路径太长,是不是会打开失败?是的话有什么方式能解决呢? 今天发现,如果我给的路径很长 是会打开失败的 谢谢~~~
[解决办法]
文件路径最长:MAX_PATH = 260
打开路径最好是 \\windiows\\FileName\\````````
双斜杠
[解决办法]
CreateFile
The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object:
files
pipes
mailslots
communications resources
disk devices (Windows NT only)
consoles
directories (open only)
HANDLE CreateFile(
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// pointer to security attributes
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to
// copy
);
Parameters
lpFileName
Pointer to a null-terminated string that specifies the name of the object (file, pipe, mailslot, communications resource, disk device, console, or directory) to create or open.
If *lpFileName is a path, there is a default string size limit of MAX_PATH characters. This limit is related to how the CreateFile function parses paths.
Windows NT: You can use paths longer than MAX_PATH characters by calling the wide (W) version of CreateFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing. This lets you use paths that are nearly 32,000 Unicode characters long. However, each component in the path cannot be more than MAX_PATH characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps".
……