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. convert BSTR to LPSTR?

convert BSTR to LPSTR?

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

    Hi. I am using a listview in a win32 api application... I want to set the text of the listview item. I do this: // LvItem.pszText= (LPSTR)_bstr_t(RsITEM(pSet,"FILE_NAME")); // it displays some junk characters... The listview works normally and there isnt any problem with the database nor with the data collection (made with RsITEM(pSet,"FILE_NAME") ) ... Thank you very much in advance for your answers... Well... I am a beginner ...

    J 1 Reply Last reply
    0
    • S Scozturk

      Hi. I am using a listview in a win32 api application... I want to set the text of the listview item. I do this: // LvItem.pszText= (LPSTR)_bstr_t(RsITEM(pSet,"FILE_NAME")); // it displays some junk characters... The listview works normally and there isnt any problem with the database nor with the data collection (made with RsITEM(pSet,"FILE_NAME") ) ... Thank you very much in advance for your answers... Well... I am a beginner ...

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      You can't simply cast a BSTR to LPSTR because they are different formats. Try using one of ATL conversion macros

      LvItem.pszText = OLE2T(_bstr_t(RsITEM(pSet,"FILE_NAME")));

      Or assign the BSTR to a CString, which will do the conversion for you

      CString sAux = _bstr_t(RsITEM(pSet,"FILE_NAME"));
      LvItem.pszText = sAux;

      Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

      S 1 Reply Last reply
      0
      • J Jose Lamas Rios

        You can't simply cast a BSTR to LPSTR because they are different formats. Try using one of ATL conversion macros

        LvItem.pszText = OLE2T(_bstr_t(RsITEM(pSet,"FILE_NAME")));

        Or assign the BSTR to a CString, which will do the conversion for you

        CString sAux = _bstr_t(RsITEM(pSet,"FILE_NAME"));
        LvItem.pszText = sAux;

        Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

        S Offline
        S Offline
        Scozturk
        wrote on last edited by
        #3

        Ok I used the second one and it worked! Thanks a lot! Well... I am a beginner ...

        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