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. About the path

About the path

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
19 Posts 7 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.
  • C capint

    I use class CImage to load & save file. I see that it requires the path with "\\" but when I get the path of the desktop image, it's the path with "\". How can I handle it ? Plz help me :rose:

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #2

    the \\ is required only when you hard code the \ character, to escape it (so that the single \ doesn't escape the character next to it. but when you get a string, it's already constructed, thus no need for modify it.

    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    C 1 Reply Last reply
    0
    • T toxcct

      the \\ is required only when you hard code the \ character, to escape it (so that the single \ doesn't escape the character next to it. but when you get a string, it's already constructed, thus no need for modify it.

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      C Offline
      C Offline
      capint
      wrote on last edited by
      #3

      I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?

      T C D 3 Replies Last reply
      0
      • C capint

        I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #4

        do you understand when I say "hard coding the string" ??? it means when you write the path yourself from within the source code... so typing Image.Load("D:\\Test.bmp") is hard coding the path, thus you need to escape the \ char into '\\'. also, writing Image.Load("D:\Test.bmp") is incorrect because the \ is in fact escaping the character next to it, so the compiler tries to understand '\t' as a single character (and as it exists, it will write it - the tab character - in the string between ':' and 'e'). now, if you get that path from an "Open File" dialog for instance, you wont have to iterate over that string to replace every \ with \\. get it now ?

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        1 Reply Last reply
        0
        • C capint

          I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #5

          Have you? Try to look at [^]. But you really need a good tutorial on C programming language. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          1 Reply Last reply
          0
          • C capint

            I use class CImage to load & save file. I see that it requires the path with "\\" but when I get the path of the desktop image, it's the path with "\". How can I handle it ? Plz help me :rose:

            S Offline
            S Offline
            sashoalm
            wrote on last edited by
            #6

            you could alternatively use / , most windows functions accept it, and the standard C library functions automatically convert it. \\ is ugly especially in long paths.

            C 1 Reply Last reply
            0
            • C capint

              I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              capint wrote:

              Image.Load("D:\Test.bmp") <-- can't load

              Because D:est.bmp (or maybe D:<tab>est.bmp) is what actually gets sent as the argument to Load().

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              C 1 Reply Last reply
              0
              • S sashoalm

                you could alternatively use / , most windows functions accept it, and the standard C library functions automatically convert it. \\ is ugly especially in long paths.

                C Offline
                C Offline
                capint
                wrote on last edited by
                #8

                I still can't understand. I know about escape sequences :^) U mean that the path we receive from window functions is OK ( we don't need to replace although they just have "\"), is that right ?

                D 1 Reply Last reply
                0
                • C capint

                  I still can't understand. I know about escape sequences :^) U mean that the path we receive from window functions is OK ( we don't need to replace although they just have "\"), is that right ?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  capint wrote:

                  U mean that the path we receive from window functions is OK

                  Yes, because those are not being seen by the compiler. What happens at runtime is completely different.

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  C 1 Reply Last reply
                  0
                  • D David Crow

                    capint wrote:

                    U mean that the path we receive from window functions is OK

                    Yes, because those are not being seen by the compiler. What happens at runtime is completely different.

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    C Offline
                    C Offline
                    capint
                    wrote on last edited by
                    #10

                    My problem is that. I receive the string from the function SystemParametersInfo and I use that string to load by Image.Load. It doesn't work :(

                    D 1 Reply Last reply
                    0
                    • C capint

                      My problem is that. I receive the string from the function SystemParametersInfo and I use that string to load by Image.Load. It doesn't work :(

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      capint wrote:

                      It doesn't work

                      Then something else is wrong. Does the file actually exist? What does Load() return?

                      "Love people and use things, not love things and use people." - Unknown

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      C 1 Reply Last reply
                      0
                      • D David Crow

                        capint wrote:

                        It doesn't work

                        Then something else is wrong. Does the file actually exist? What does Load() return?

                        "Love people and use things, not love things and use people." - Unknown

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        C Offline
                        C Offline
                        capint
                        wrote on last edited by
                        #12

                        All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works

                        D M 2 Replies Last reply
                        0
                        • C capint

                          All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #13

                          Which statement is failing?

                          "Love people and use things, not love things and use people." - Unknown

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          C 1 Reply Last reply
                          0
                          • D David Crow

                            Which statement is failing?

                            "Love people and use things, not love things and use people." - Unknown

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            C Offline
                            C Offline
                            capint
                            wrote on last edited by
                            #14

                            No statement is failing. It just doesn't do anything. Actually, when I replace "\" by "/", it works. But I still wonder :sigh:

                            D 1 Reply Last reply
                            0
                            • D David Crow

                              capint wrote:

                              Image.Load("D:\Test.bmp") <-- can't load

                              Because D:est.bmp (or maybe D:<tab>est.bmp) is what actually gets sent as the argument to Load().

                              "Love people and use things, not love things and use people." - Unknown

                              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                              C Offline
                              C Offline
                              CPallini
                              wrote on last edited by
                              #15

                              DavidCrow wrote:

                              D:est.bmp (or maybe D:est.bmp)

                              or even D:est.bmp! :-D (BTW I got what you meant, anyway kidding is irresistible to me...)

                              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                              R 1 Reply Last reply
                              0
                              • C capint

                                No statement is failing. It just doesn't do anything. Actually, when I replace "\" by "/", it works. But I still wonder :sigh:

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #16

                                capint wrote:

                                No statement is failing.

                                How are you verifying this?

                                capint wrote:

                                Actually, when I replace "\" by "/", it works. But I still wonder

                                Single slashes (like those used on Unix machines) can be used in place of double backslashes.

                                "Love people and use things, not love things and use people." - Unknown

                                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                1 Reply Last reply
                                0
                                • C capint

                                  All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works

                                  M Offline
                                  M Offline
                                  Member 4194593
                                  wrote on last edited by
                                  #17

                                  You realize, of course, that the path can be up to 260 characters long?

                                  1 Reply Last reply
                                  0
                                  • C CPallini

                                    DavidCrow wrote:

                                    D:est.bmp (or maybe D:est.bmp)

                                    or even D:est.bmp! :-D (BTW I got what you meant, anyway kidding is irresistible to me...)

                                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                                    R Offline
                                    R Offline
                                    Rajesh R Subramanian
                                    wrote on last edited by
                                    #18

                                    :laugh: You're a such a bad guy.

                                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                                    C 1 Reply Last reply
                                    0
                                    • R Rajesh R Subramanian

                                      :laugh: You're a such a bad guy.

                                      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                                      C Offline
                                      C Offline
                                      CPallini
                                      wrote on last edited by
                                      #19

                                      I know, buddy! :-D

                                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                                      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