How to get name associated with open HANDLE

后端 未结 7 497
终归单人心
终归单人心 2020-11-27 06:13

What\'s the easiest way to get the filename associated with an open HANDLE in Win32?

相关标签:
7条回答
  • 2020-11-27 06:46

    If you need to do this on Win32 pre-Vista or Server 2008, look at the GetMappedFileName(...) function, which is one of the best kept secrets in Win32. WIth a little C/C++-fu, you can memory map a small portion of the file in question, and then pass that handle to this function.

    Also, on Win32, you cannot really delete a file that is open (the open/unlink issue mentioned on another answer) - you can mark it for deletion on close, but it will still hang around until its last open handle is closed. Dunno if mapping (via mmap(...)) the file in this case would help, because it has to point back to a physical file...

    -=- James.

    0 讨论(0)
提交回复
热议问题