CreateFile and long device name

I use CreateFile to open the device. Everything is fine if the device name is too long.

The documentation says:

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 function version and add "\\? \" To the path. For more information, see File Naming, Paths, and Namespaces.

I try to use CreateFileW and add "\\? \" To the path, but I get an invalid handle and

The system cannot find the path specified.

in GetLastError ().

So, is this trick only valid for file names, not device names? Are there any other ways to avoid this problem?

UPD1: The device name without adding is as follows:

\\\ device \ EndsBy: \ name1.exe | EndsBy:. \ Name2.exe.

the code:

CreateFileW (path .c_str (), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0));

+4
source share
2 answers

The prefix \\?sends paths directly to the file system without preprocessing.

The prefix \\.bypasses the file namespace and uses the Win32 device namespace.

They have separate goals and cannot be mixed.

You can try it yourself. For example, this will open the null device:

HANDLE hDevice = ::CreateFileW(L"\\\\.\\NUL", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);

L"\\\\?\\\\.\\NUL", .

, , \\? .

+3

, :

  • \\.\ \\?\; , , , .

  • Windows 8, CreateFile2 \\.\; .

  • , , , , .

  • DefineDosDevice \\.\myalias CreateFile. , QueryDosDevice . , DDD_RAW_TARGET_PATH.

  • NtCreateFile. CreateFile \\.\devicename, NtCreateFile. , API Windows.

+2

Source: https://habr.com/ru/post/1545136/


All Articles