Windows API's CreateFile with CFile gives invalid path error if used drives created with SUBST

Dada Khalandhar Gooty 0 Reputation points
2024-05-03T12:58:05.9266667+00:00

A drive is created for a folder using SUBST command. We have a Windows application which reads contents of the and performs some operations. Application does not give any error when read the file path is from actual drive. But when try to read from drive created using SUBST, it gives invalid path error. Please find the following code snippet for it. Error occurs at the last line.

 hFile = CreateFile(
        ("\\\\?\\" + std::string(file_path,
        GENERIC_READ,            
        FILE_SHARE_READ,         
        NULL,                    
        OPEN_EXISTING,           
        FILE_ATTRIBUTE_NORMAL,   
        NULL);                   

    if (hFile == INVALID_HANDLE_VALUE) {
        CloseHandle(hFile);
        return;
    }

    fd = new CFile(hFile);

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,462 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,580 questions
{count} votes