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. C / C++ / MFC
  3. How Can convert BSTR to LPCSTR OR vice versa!

How Can convert BSTR to LPCSTR OR vice versa!

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 4 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.
  • B Offline
    B Offline
    bluestn
    wrote on last edited by
    #1

    How Can convert BSTR to LPCSTR OR vice versa!

    C E 2 Replies Last reply
    0
    • B bluestn

      How Can convert BSTR to LPCSTR OR vice versa!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      CString does it for you - it can be constructed from a BSTR and AllocSysString returns a BSTR. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      V 1 Reply Last reply
      0
      • C Christian Graus

        CString does it for you - it can be constructed from a BSTR and AllocSysString returns a BSTR. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

        V Offline
        V Offline
        Venkat Raghavan
        wrote on last edited by
        #3

        Use _bstr_t to handle conversion from BSTR to const wchar_t*/const char*. _bstr_t is part of VC6.0's compiler COM support classes. Defined in . -- Venkat

        1 Reply Last reply
        0
        • B bluestn

          How Can convert BSTR to LPCSTR OR vice versa!

          E Offline
          E Offline
          Erik Thompson
          wrote on last edited by
          #4

          Define USES_CONVERSION; at the top of the method implementation you are trying to do the conversion in. then use W2T void foo(BSTR bstrVariable) { USES_CONVERSION; // conversion is done to the stack so don't delete on function exit // and don't use pointer outside of method. LPCTSTR pcstrVariable = W2T(bstrVariable); // TODO: do work with string. } Cheers, -Erik ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ My thoughts are my own and reflect on no other.

          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