convert a BSTR data type to std::string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karthik

    convert a BSTR data type to std::string

    Hello,

    How can I convert a BSTR data type to std::string??? Thanks a much!

    Karthik

  • Howard

    #2
    Re: convert a BSTR data type to std::string


    "Karthik" <karthik.t@gmai l.com> wrote in message
    news:1121289967 .573625.124080@ g43g2000cwa.goo glegroups.com.. .[color=blue]
    > Hello,
    >
    > How can I convert a BSTR data type to std::string??? Thanks a much!
    >
    > Karthik
    >[/color]

    Ask in a microsoft newsgroup. I believe BSTR is a microsoft-defined type.

    (But, have you tried simply assigning from your BSTR variable to your
    std::string variable, or creating a std::string with the BSTR as the
    std::string's constructor's parameter?)

    -Howard


    Comment

    • Heinz Ozwirk

      #3
      Re: convert a BSTR data type to std::string


      "Karthik" <karthik.t@gmai l.com> schrieb im Newsbeitrag
      news:1121289967 .573625.124080@ g43g2000cwa.goo glegroups.com.. .[color=blue]
      > How can I convert a BSTR data type to std::string??? Thanks a much![/color]

      A BSTR - if you are talking about the Microsoft thing - basically is a
      unicode string. To convert it into an std::string you have to use functions
      like wcstombs or WideCharToMulti Byte. But you should better use std::wstring
      instead of std::string, or you cannot convert all possible characters in a
      BSTR.

      HTH
      Heinz


      Comment

      • Jonathan Mcdougall

        #4
        Re: convert a BSTR data type to std::string

        > How can I convert a BSTR data type to std::string??? Thanks a much!

        Seems a BSTR is a double-byte string, so you won't be able to put it in
        a std::string. Use std::wstring instead. Something like

        void f(BSTR ms_str)
        {
        std::wstring ws(ms_str);
        }

        should work, but you would be better served in a microsoft newgroup.

        Jonathan

        Comment

        • Default User

          #5
          Re: convert a BSTR data type to std::string



          Howard wrote:[color=blue]
          > "Karthik" <karthik.t@gmai l.com> wrote in message
          > news:1121289967 .573625.124080@ g43g2000cwa.goo glegroups.com.. .[color=green]
          > > Hello,
          > >
          > > How can I convert a BSTR data type to std::string??? Thanks a much!
          > >
          > > Karthik
          > >[/color]
          >
          > Ask in a microsoft newsgroup. I believe BSTR is a microsoft-defined type.[/color]

          That's a good suggestion.
          [color=blue]
          > (But, have you tried simply assigning from your BSTR variable to your
          > std::string variable, or creating a std::string with the BSTR as the
          > std::string's constructor's parameter?)[/color]

          I'm guessing that it probably won't work, based on what I read here:



          This may help the OP.



          Brian

          Comment

          • Phlip

            #6
            Re: convert a BSTR data type to std::string

            Karthik wrote:
            [color=blue]
            > How can I convert a BSTR data type to std::string??? Thanks a much![/color]

            #include <comdef.h>

            std::string myString = _bstr_t (myBSTR);

            Future BSTR questions belong on some other newsgroup blah blah blah...

            --
            Phlip



            Comment

            Working...