CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    [RESOLVED] Retrieve filename from HANDLE

    I got the HANDLE to a file, and I need to find the filename associated.


    • GetFileInformationByHandle returns other information about file, but not filename.
    • I don't want to use NtQueryInformationFile
    • Cannot use CFile(HANDLE), CFile::GetFileName, since it needs open file-handle. I just have file-handle (no open file).
    • This is not appealing me:
      http://msdn.microsoft.com/en-us/libr...89(VS.85).aspx
    For now, I cannot disclose "how" I am getting this HANDLE.

    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Retrieve filename from HANDLE

    Quote Originally Posted by Ajay Vijay View Post
    I got the HANDLE to a file, and I need to find the filename associated. [...]
    One question: how did you get the HANDLE to that file?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Retrieve filename from HANDLE

    I already mentioned, that I cannot tell how I got the handle (at least for now!).
    Thus, for now I've used the MSDN's code to retrieve the filename.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Retrieve filename from HANDLE

    Ovidiu,
    Ajay already wrote that he "cannot disclose 'how' ..." he is "getting this HANDLE".

    And I agree with you that this "how" could help...
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Retrieve filename from HANDLE

    Quote Originally Posted by VictorN View Post
    Ovidiu,
    Ajay already wrote that he "cannot disclose 'how' ..." he is "getting this HANDLE".
    Oh, sorry! Is a special question/quiz for Chuck Norris, isn't it?
    Last edited by ovidiucucu; September 26th, 2009 at 09:35 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Retrieve filename from HANDLE

    Quote Originally Posted by ovidiucucu View Post
    Oh, sorry! Is a special question/quiz for Chuck Norris, isn't it?
    LOL!

    Ajay! How have you resolved this handle/filename problem?
    Victor Nijegorodov

  7. #7
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] Retrieve filename from HANDLE

    Well, right now I am using this approach: http://msdn.microsoft.com/en-us/libr...89(VS.85).aspx

    Okay, I am going to write an article for CodeGuru.com, and for that I needed to find out name of file, associated with handle. But I want to keep the topic private to myself, till I write and submit for posting.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: [RESOLVED] Retrieve filename from HANDLE

    Quote Originally Posted by Ajay Vijay View Post
    Well, right now I am using this approach: http://msdn.microsoft.com/en-us/libr...89(VS.85).aspx

    Okay, I am going to write an article for CodeGuru.com, and for that I needed to find out name of file, associated with handle. But I want to keep the topic private to myself, till I write and submit for posting.
    Well, We'll wait for your article...
    BTW, the link you provided is wrong.
    Victor Nijegorodov

  9. #9
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] Retrieve filename from HANDLE

    Quote Originally Posted by VictorN View Post
    BTW, the link you provided is wrong.
    I just copied and pasted from the link in the first post. Please navigate from the link in first post.

    I am wondering, why I need tell the same thing twice?
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: [RESOLVED] Retrieve filename from HANDLE

    Okay, Ajay! I'm looking forward for the article. It seems to be an interesting one.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  11. #11
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] Retrieve filename from HANDLE

    One thing! I've not written a single word for the article as of now. May take few days to finish.
    The article (on multithreading), that I've already submitted for posting isn't the one I am working on.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: [RESOLVED] Retrieve filename from HANDLE

    Quote Originally Posted by Ajay Vijay View Post
    I got the HANDLE to a file, and I need to find the filename associated.


    • I don't want to use NtQueryInformationFile


    Sounds... like not very reasonable. Afraid you have no other choice. I wouldn't be surprised if I found out that GetMappedFileName uses NtQueryInformationFile internally.

    Besides, I'd like to hear about the reason of such a dislike to a very basic API. (Please, don't tell me it's just because the approach is not a brand new one. )
    Best regards,
    Igor

  13. #13
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] Retrieve filename from HANDLE

    Because it's an undocumented function. Not mentioned anywhere in MSDN. I found it under undocumented.ntinternals.net. Further to that, other similar APIs (like NtQueryInformationProcess), says something in MSDN:
    Quote Originally Posted by MSDN
    [NtQueryInformationProcess may be altered or unavailable in future versions of Windows. Applications should use the alternate functions listed in this topic.]
    I am still a user-mode programmer, I cannot think of these APIs till I start with kernel-mode programming!
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: [RESOLVED] Retrieve filename from HANDLE

    Because it's an undocumented function. Not mentioned anywhere in MSDN. I found it under undocumented.ntinternals.net.
    Oh, really?

    NtQueryInformationFile
    ZwQueryInformationFile

    I am still a user-mode programmer, I cannot think of these APIs till I start with kernel-mode programming!
    That's too bad. I am a user-mode programmer too, and I never stop thinking of the NtXxxx functions, as they are legal portals from user mode to kernel mode.
    Best regards,
    Igor

  15. #15
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] Retrieve filename from HANDLE

    The APIs were in Kernel-Mode Driver Architecture group, and I would not use it for the sake of article.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured