How to get name associated with open HANDLE

后端 未结 7 569
终归单人心
终归单人心 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:28

    On unixes there is no real way of reliably doing this. In unix with the traditional unix filesystem, you can open a file and then unlink it (remove its entry from the directory) and use it, at which point the name isn't stored anywhere. In addition, because a file may have multiple hardlinks into the filesystem, each of the names are equivalent, so once you've got just the open handle it wouldn't be clear which filename you should map back towards.

    So, you may be able to do this on Win32 using the other answers, but should you ever need to port the application to a unix enviornment, you'll be out of luck. My advice to you is to refactor your program, if possible, so that you don't need the OS to be able to maintain an open resource to filename connection.

提交回复
热议问题