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. COM
  4. BSTR

BSTR

Scheduled Pinned Locked Moved COM
c++sysadminhelpquestion
7 Posts 6 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.
  • N Offline
    N Offline
    newbe
    wrote on last edited by
    #1

    Hello, can somebody please help me: i'm trying to write a string to a file serverside. and i want to get the string back. So i use the next function: MIDL :write [in]BSTR message cpp: HRESULT Write(BSTR message) { //code to write to a file on the server } can u please explane how the BSTR type works and how can i convert it to a normal string

    C E P Y 4 Replies Last reply
    0
    • N newbe

      Hello, can somebody please help me: i'm trying to write a string to a file serverside. and i want to get the string back. So i use the next function: MIDL :write [in]BSTR message cpp: HRESULT Write(BSTR message) { //code to write to a file on the server } can u please explane how the BSTR type works and how can i convert it to a normal string

      C Offline
      C Offline
      Carlos Antollini
      wrote on last edited by
      #2

      CString str = _T("") str = message; Carlos Antollini. Sonork ID 100.10529 cantollini

      N 1 Reply Last reply
      0
      • N newbe

        Hello, can somebody please help me: i'm trying to write a string to a file serverside. and i want to get the string back. So i use the next function: MIDL :write [in]BSTR message cpp: HRESULT Write(BSTR message) { //code to write to a file on the server } can u please explane how the BSTR type works and how can i convert it to a normal string

        E Offline
        E Offline
        Ernest Laurentin
        wrote on last edited by
        #3

        One of the easiest way to use the BSTR type as normal string, in my opinion is to use the compiler string type: _bstr_t Use like this:

        HRESULT Write(BSTR message)
        {
        _tprintf(TEXT("Message:%s\r\n", (LPCTSTR) _bstr_t(message));
        }

        You can look at the description for _bstr_t in MDSN for more help. It can also convert ASCII string to Unicode. You may want to use conversion macro.

        HRESULT Write(BSTR message)
        {
        USES_CONVERSION;
        LPCTSTR lpszNormal = OLE2CT(message);
        _tprintf(TEXT("Message:%s\r\n", (LPCTSTR) lpszNormal);
        }

        N 1 Reply Last reply
        0
        • C Carlos Antollini

          CString str = _T("") str = message; Carlos Antollini. Sonork ID 100.10529 cantollini

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          CString str(message)

          1 Reply Last reply
          0
          • E Ernest Laurentin

            One of the easiest way to use the BSTR type as normal string, in my opinion is to use the compiler string type: _bstr_t Use like this:

            HRESULT Write(BSTR message)
            {
            _tprintf(TEXT("Message:%s\r\n", (LPCTSTR) _bstr_t(message));
            }

            You can look at the description for _bstr_t in MDSN for more help. It can also convert ASCII string to Unicode. You may want to use conversion macro.

            HRESULT Write(BSTR message)
            {
            USES_CONVERSION;
            LPCTSTR lpszNormal = OLE2CT(message);
            _tprintf(TEXT("Message:%s\r\n", (LPCTSTR) lpszNormal);
            }

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            CComBSTR

            1 Reply Last reply
            0
            • N newbe

              Hello, can somebody please help me: i'm trying to write a string to a file serverside. and i want to get the string back. So i use the next function: MIDL :write [in]BSTR message cpp: HRESULT Write(BSTR message) { //code to write to a file on the server } can u please explane how the BSTR type works and how can i convert it to a normal string

              P Offline
              P Offline
              pba_
              wrote on last edited by
              #6

              MultiByteToWideChar / WideCharToMultiByte or mbstowcs / wcstombs ;)

              1 Reply Last reply
              0
              • N newbe

                Hello, can somebody please help me: i'm trying to write a string to a file serverside. and i want to get the string back. So i use the next function: MIDL :write [in]BSTR message cpp: HRESULT Write(BSTR message) { //code to write to a file on the server } can u please explane how the BSTR type works and how can i convert it to a normal string

                Y Offline
                Y Offline
                yamini
                wrote on last edited by
                #7

                There are 2ways to do this The first method uses the OLE2T() for BSTR conversion to string. The second method uses _bstr_t for conversion. ******************************************************#inclu#include #include #include void main() { BSTR b=L"StringConversion"; //BSTR string USES_CONVERSION; //First method of Conversion cout<<"String :"<

                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