how to use SHCreateStreamOnFileEx to create a file with a long UNC path


When I use SHCreateStreamOnFileEx to create a stream with a long UNC path (WCHAR, like \?\UNC\localhost\long.......long.....path\abc.txt), I got error "0x80070003 The system cannot find the path specified. ".


Remarks The SHCreateStreamOnFileEx function extends the semantics of the STGM flags and produces the same effect as calling the CreateFile function.

From, *lpFileName [in] 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.*

Anyone know how to let SHCreateStreamOnFileEx support long UNC path?


asked on Stack Overflow Nov 28, 2013 by RickeyShao

1 Answer


The CreateFile function requires you to convert \\server\share\path to \\?\UNC\server\share\path, that's two backslashes in the beginning. If that doesn't work, then SHCreateStreamOnFileEx doesn't support the long paths.

answered on Stack Overflow Jun 9, 2014 by Sean Hall

User contributions licensed under CC BY-SA 3.0