Share via

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 development | Windows API - Win32
Developer technologies | C++
Developer technologies | 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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.