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. How to read the contents of a VARIANT ?

How to read the contents of a VARIANT ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structurestutorial
4 Posts 3 Posters 2 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.
  • L Offline
    L Offline
    LindeA
    wrote on last edited by
    #1

    Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix

    C P 2 Replies Last reply
    0
    • L LindeA

      Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix

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

      You're assuming v1 is a string. It maybe something else (you have to check the VARIANT's vt field). Moreover, why don't you check the SafeArrayGetElement return value? :)

      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]

      L 1 Reply Last reply
      0
      • L LindeA

        Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        LindeA wrote:

        _bstr_t s1(v1);

        In addition to checks suggested by CPallini, I suggest to you to read VARIANT's doucmentation. If it really contains strings, it can be used as v1.bstr.

        1 Reply Last reply
        0
        • C CPallini

          You're assuming v1 is a string. It maybe something else (you have to check the VARIANT's vt field). Moreover, why don't you check the SafeArrayGetElement return value? :)

          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]

          L Offline
          L Offline
          LindeA
          wrote on last edited by
          #4

          I did what you suggest : the return value of SafeArrayGetElement is S_OK v1.vt = 0x95d4 I have seen a VB example using this GetAllProperties method, and there they simply access it with names(i), and treat it as a string ( it stands for a Property Name ) How can I translate this into C++ ?

          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