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_t to CStringArray

_variant_t to CStringArray

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 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.
  • D Offline
    D Offline
    Davitor
    wrote on last edited by
    #1

    Hi All i have

    _variant_t data

    type variable,which have contain 10 values.Like this

    [0,0] = BSTR = 0x0017a66c "Name"
    [0,1] = BSTR = 0x0017a6ec "Age"
    [0,2] = BSTR = 0x0017a6ec "Class"
    ...

    data is a SAFEARRAY containing BSTR elements.so how can i convert _variant_ to CStringArray? Plz help me

    C S 2 Replies Last reply
    0
    • D Davitor

      Hi All i have

      _variant_t data

      type variable,which have contain 10 values.Like this

      [0,0] = BSTR = 0x0017a66c "Name"
      [0,1] = BSTR = 0x0017a6ec "Age"
      [0,2] = BSTR = 0x0017a6ec "Class"
      ...

      data is a SAFEARRAY containing BSTR elements.so how can i convert _variant_ to CStringArray? Plz help me

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      See for instance [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • D Davitor

        Hi All i have

        _variant_t data

        type variable,which have contain 10 values.Like this

        [0,0] = BSTR = 0x0017a66c "Name"
        [0,1] = BSTR = 0x0017a6ec "Age"
        [0,2] = BSTR = 0x0017a6ec "Class"
        ...

        data is a SAFEARRAY containing BSTR elements.so how can i convert _variant_ to CStringArray? Plz help me

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        There are useful classes wrapping SAFEARRAYs - see here[^] and here[^].

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        D 1 Reply Last reply
        0
        • S Stuart Dootson

          There are useful classes wrapping SAFEARRAYs - see here[^] and here[^].

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          D Offline
          D Offline
          Davitor
          wrote on last edited by
          #4

          thanks for reply but it's not helpfull for my problem.So plz help me

          S 1 Reply Last reply
          0
          • D Davitor

            thanks for reply but it's not helpfull for my problem.So plz help me

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            Those links are actually helpful, because they give you C++ wrappers for SAFEARRAYs that will simplify the job of converting the SAFEARRAY to some other array of strings.

            CComSafeArray<BSTR> safearrayOfBstr(((VARIANT)data).parray);

            will wrap the SAFEARRAY contained in the VARIANT. You can then use the CComSafeArray methods to access the SAFEARRAY data. This article[^] is very useful, because it gives easier access to 2D SAFEARRAYs, which is what you've got here. Thing is, it's up to you to do that final step of converting to your CStringArray - but all you need to do is iterate through the relevant elements of the SAFEARRAY, extract the BSTR, convert it to a CString and store that in your CStringArray - not tricky, really!

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            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