Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFileDialog strange GetFileName

CFileDialog strange GetFileName

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I have following code:

    CFileDialog fileDlg(TRUE, \_T("\*"), NULL, OFN\_PATHMUSTEXIST | OFN\_OVERWRITEPROMPT, \_T("All files (\*.\*)|\*.\*||"), NULL);
    if(IDOK == fileDlg.DoModal())
    	TRACE(">>>%s\\n", fileDlg.GetFileName());
    

    and when I select a file, no mater what kind of file, I get:

    >>>D

    that is all ... why ? What I have done wrong here ?

    J 1 Reply Last reply
    0
    • _ _Flaviu

      I have following code:

      CFileDialog fileDlg(TRUE, \_T("\*"), NULL, OFN\_PATHMUSTEXIST | OFN\_OVERWRITEPROMPT, \_T("All files (\*.\*)|\*.\*||"), NULL);
      if(IDOK == fileDlg.DoModal())
      	TRACE(">>>%s\\n", fileDlg.GetFileName());
      

      and when I select a file, no mater what kind of file, I get:

      >>>D

      that is all ... why ? What I have done wrong here ?

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You are passing an ANSI string to the TRACE macro. Therefore, an ANSI string is expected for the %s parameter but you have a Unicode build and fileDlg.GetFileName() returns a wide string. So you should use the _T() macro also for the TRACE argument:

      TRACE(_T(">>>%s\n"), fileDlg.GetFileName());

      See also the examples at MFC Debugging Techniques[^].

      _ 1 Reply Last reply
      0
      • J Jochen Arndt

        You are passing an ANSI string to the TRACE macro. Therefore, an ANSI string is expected for the %s parameter but you have a Unicode build and fileDlg.GetFileName() returns a wide string. So you should use the _T() macro also for the TRACE argument:

        TRACE(_T(">>>%s\n"), fileDlg.GetFileName());

        See also the examples at MFC Debugging Techniques[^].

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Thank you. That was the problem.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups