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. _bstr_t to string-newbie

_bstr_t to string-newbie

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 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.
  • A Offline
    A Offline
    antonaras
    wrote on last edited by
    #1

    Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far

    J M B T 4 Replies Last reply
    0
    • A antonaras

      Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      I actually know this is simple, but I forget the answer. I would repost this question in the COM forum if I was you. INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

      1 Reply Last reply
      0
      • A antonaras

        Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        See The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        A 1 Reply Last reply
        0
        • A antonaras

          Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          Mr. Dunn already pointed you to his FAQ which is probably the best resource available on CP but just in case, here are some ways you can get it done. NOTE: These will only work if the BSTR does not contain embedded NULL's as would occur in a BYTE array. If you are sure you are dealing with null terminated strings in the BSTR like when using MSXML, these will get you by. // Using the CString constructor _bstr_t bstrTemp("This is a test\n"); CString sTemp1((BSTR)bstrTemp); TRACE(sTemp1); // For when you don't have the luxury of using the constructor CString sTemp2; sTemp2.Format("%s",(LPCTSTR)bstrTemp); TRACE(sTemp2);

          A 1 Reply Last reply
          0
          • M Michael Dunn

            See The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

            A Offline
            A Offline
            antonaras
            wrote on last edited by
            #5

            Cool Guide!!!! very good has everything thanks for showing me the way

            1 Reply Last reply
            0
            • B bob16972

              Mr. Dunn already pointed you to his FAQ which is probably the best resource available on CP but just in case, here are some ways you can get it done. NOTE: These will only work if the BSTR does not contain embedded NULL's as would occur in a BYTE array. If you are sure you are dealing with null terminated strings in the BSTR like when using MSXML, these will get you by. // Using the CString constructor _bstr_t bstrTemp("This is a test\n"); CString sTemp1((BSTR)bstrTemp); TRACE(sTemp1); // For when you don't have the luxury of using the constructor CString sTemp2; sTemp2.Format("%s",(LPCTSTR)bstrTemp); TRACE(sTemp2);

              A Offline
              A Offline
              antonaras
              wrote on last edited by
              #6

              Thanks bob for the help and the info but u are right that article Dunn gave me is more than helpful Thanks again appreciate the help

              1 Reply Last reply
              0
              • A antonaras

                Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                antonaras wrote:

                Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string

                _bstr_t hi("alok");  std::string str((LPCTSTR)hi) ;

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                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