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 std::string

_bstr_t to std::string

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 3 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.
  • G Offline
    G Offline
    gmallax
    wrote on last edited by
    #1

    Hi, how to convert from _bstr_t to std::string data type? Thanx

    S 1 Reply Last reply
    0
    • G gmallax

      Hi, how to convert from _bstr_t to std::string data type? Thanx

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Use _bstr_t's char* extraction operator:

      _bstr_t bStr(L"Hello");
      std::string str((char*)bStr);

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      G N 2 Replies Last reply
      0
      • S Stuart Dootson

        Use _bstr_t's char* extraction operator:

        _bstr_t bStr(L"Hello");
        std::string str((char*)bStr);

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

        G Offline
        G Offline
        gmallax
        wrote on last edited by
        #3

        yes.Thanx :)

        1 Reply Last reply
        0
        • S Stuart Dootson

          Use _bstr_t's char* extraction operator:

          _bstr_t bStr(L"Hello");
          std::string str((char*)bStr);

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #4

          Stuart Dootson wrote:

          Use _bstr_t's char* extraction operator:

          Haven't used _bstr_t at all, but from the documentation I would say the extraction operator merely gives a pointer to the internal data buffer. That's most probably not what he needs. He should convert the UTF-16 encoded _bstr_t string to some multibyte encoding first to store it to std::string.

          utf8-cpp

          S 1 Reply Last reply
          0
          • N Nemanja Trifunovic

            Stuart Dootson wrote:

            Use _bstr_t's char* extraction operator:

            Haven't used _bstr_t at all, but from the documentation I would say the extraction operator merely gives a pointer to the internal data buffer. That's most probably not what he needs. He should convert the UTF-16 encoded _bstr_t string to some multibyte encoding first to store it to std::string.

            utf8-cpp

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            _bstr_t keeps an internal ASCII copy of the BSTR which is populated on demand. This copy is the internal data buffer that the char* extractor returns a pointer to. Therefore the answer I gave is what the OP needs and wants.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

            N 1 Reply Last reply
            0
            • S Stuart Dootson

              _bstr_t keeps an internal ASCII copy of the BSTR which is populated on demand. This copy is the internal data buffer that the char* extractor returns a pointer to. Therefore the answer I gave is what the OP needs and wants.

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

              N Offline
              N Offline
              Nemanja Trifunovic
              wrote on last edited by
              #6

              Stuart Dootson wrote:

              _bstr_t keeps an internal ASCII copy of the BSTR which is populated on demand

              Interesting. Is it really ASCII, or whatever the system code page is ("ANSI")?

              utf8-cpp

              S 1 Reply Last reply
              0
              • N Nemanja Trifunovic

                Stuart Dootson wrote:

                _bstr_t keeps an internal ASCII copy of the BSTR which is populated on demand

                Interesting. Is it really ASCII, or whatever the system code page is ("ANSI")?

                utf8-cpp

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                No idea - didn't look quite that far into the source (comutil.h in your VS distribution, if you want to look).

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

                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