I want that a non-.NET application access a Memory Mapped file, but this application is not aware of the existence of Memory Mapped files, so I need the file path. It is possible?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You can use the GetMappedFileName function to get the path to a memory mapped file when it is mapped. This of course requires that the memory mapped file is actually backed by a physical file, but the question makes it vague what the situation exactly is. Did some third party library hand you a MemoryMappedFile, MemoryMappedViewAccessor or MemoryMappedViewStream, but you don't know whether it is backed by a physical file?
Here is a sample showing how one would get the filename from a MemoryMappedFile:
When I run this I get the output:
Note that the path is returned in native NT path format. If you need to convert that into a dos/win32 format, see this question: How can I convert a native (NT) pathname into a Win32 path name?
For the error when there is not file associated, the error message is a bit weird, but the error code means ERROR_FILE_INVALID, which makes sense since there is no file.
They have some samples here.
EDIT
I think this would provide the answer. Basically, it would seem some sort of memory pointer is required for memory-mapped files, and not a file system path.