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. VARIANT and CString

VARIANT and CString

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I have a function that return variant.How can I cast it to CString? Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

    D D 2 Replies Last reply
    0
    • M Mazdak

      I have a function that return variant.How can I cast it to CString? Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

      D Offline
      D Offline
      DanielO
      wrote on last edited by
      #2

      VARIANT v; CString strValue; //TCHAR sz[5]; VariantInit(&v); v.vt = VT_BSTR; v.bstrVal = strValue.AllocSysString(); //v.bstrVal = SysAllocString(sz); //do something with variant SysFreeString(v.bstrVal); VariantClear(&v); another way around Variant v; //variant gets value CString strValue(v.bstrVal); hope it helps DanielO

      M S 2 Replies Last reply
      0
      • D DanielO

        VARIANT v; CString strValue; //TCHAR sz[5]; VariantInit(&v); v.vt = VT_BSTR; v.bstrVal = strValue.AllocSysString(); //v.bstrVal = SysAllocString(sz); //do something with variant SysFreeString(v.bstrVal); VariantClear(&v); another way around Variant v; //variant gets value CString strValue(v.bstrVal); hope it helps DanielO

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thats perfect.Thanks a lot. :) Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

        1 Reply Last reply
        0
        • D DanielO

          VARIANT v; CString strValue; //TCHAR sz[5]; VariantInit(&v); v.vt = VT_BSTR; v.bstrVal = strValue.AllocSysString(); //v.bstrVal = SysAllocString(sz); //do something with variant SysFreeString(v.bstrVal); VariantClear(&v); another way around Variant v; //variant gets value CString strValue(v.bstrVal); hope it helps DanielO

          S Offline
          S Offline
          Shamoon
          wrote on last edited by
          #4

          Can any one tell m how to convert Variant to std::srting and char *

          S 1 Reply Last reply
          0
          • S Shamoon

            Can any one tell m how to convert Variant to std::srting and char *

            S Offline
            S Offline
            Stefan Pedersen
            wrote on last edited by
            #5

            use the c_str() method

            1 Reply Last reply
            0
            • M Mazdak

              I have a function that return variant.How can I cast it to CString? Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

              D Offline
              D Offline
              Daniel Turini
              wrote on last edited by
              #6

              CString s( _variant_t(FunctionReturningVariant()) ); Concussus surgo. When struck I rise.

              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