I'm using CreateFile to open device. Everything is ok untill device name is too long.
In documentation it is said:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming Files, Paths, and Namespaces.
I'm trying to use CreateFileW and prepend "\\?\" to the path, but getting invalid handle and
The system cannot find the path specified.
in GetLastError().
So, is this trick valid only for filenames, not for device names? Are there any other ways to avoid this problem?
UPD1: Device name without prepend looks like:
\\.\devicename\EndsBy:\name1.exe|EndsBy:\name2.exe.
Code:
CreateFileW(path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0));
"\\?\"
or do you actually prepend"\\\\?\\"
? – ghostofstandardspast"\\?\"
requires an absolute path to follow. It will also skip some normalization steps like processing.
and..
, or removing trailing dots and spaces. – asveikau