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. ATL / WTL / STL
  4. VARIANT convertions [modified]

VARIANT convertions [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
tutorialquestion
4 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.
  • H Offline
    H Offline
    HeartFriend
    wrote on last edited by
    #1

    i have a variable whose type is long*. i wanna assign it to a CComVariant variable. //put value into variant CComPtr< IMyInterface > spInter; long *p = (long*)spInter.p; CComVariant vt; vt.plVal = spInter.p; //how to get value from variant CComPtr< IMyInterface > spNew; spNew = (IMyInterface*)vt.plVal; (i can do this because i know the value type in variant, but how could i do if i don't know the type? should i call changetype() first?but what should i pass into ChangeType(???) as parameter? -- modified at 1:18 Wednesday 16th August, 2006

    L M 2 Replies Last reply
    0
    • H HeartFriend

      i have a variable whose type is long*. i wanna assign it to a CComVariant variable. //put value into variant CComPtr< IMyInterface > spInter; long *p = (long*)spInter.p; CComVariant vt; vt.plVal = spInter.p; //how to get value from variant CComPtr< IMyInterface > spNew; spNew = (IMyInterface*)vt.plVal; (i can do this because i know the value type in variant, but how could i do if i don't know the type? should i call changetype() first?but what should i pass into ChangeType(???) as parameter? -- modified at 1:18 Wednesday 16th August, 2006

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      An alternate way would be to Detach enclosed VARIANT. A VARIANT has a member called "VARTYPE vt". You can use this to determine type of Variant.

      S o h a i l K a d i w a l a

      1 Reply Last reply
      0
      • H HeartFriend

        i have a variable whose type is long*. i wanna assign it to a CComVariant variable. //put value into variant CComPtr< IMyInterface > spInter; long *p = (long*)spInter.p; CComVariant vt; vt.plVal = spInter.p; //how to get value from variant CComPtr< IMyInterface > spNew; spNew = (IMyInterface*)vt.plVal; (i can do this because i know the value type in variant, but how could i do if i don't know the type? should i call changetype() first?but what should i pass into ChangeType(???) as parameter? -- modified at 1:18 Wednesday 16th August, 2006

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You should pass COM interfaces at VT_UNKNOWN or VT_DISPATCH so they get properly marshaled if necessary.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        H 1 Reply Last reply
        0
        • M Michael Dunn

          You should pass COM interfaces at VT_UNKNOWN or VT_DISPATCH so they get properly marshaled if necessary.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          H Offline
          H Offline
          HeartFriend
          wrote on last edited by
          #4

          thanks guys, here is my situation. i have a class which hold a tree control(activex control), sure tree control offer setItemData(item, data), getITemData(item, &data); here data's type is converted to long*. i wanna store the interface pointer address in the item data, and get it back when i need. VARIANT DelegateGetData(item) { long *data; getItemData(item, data); CComVariant vt; vt.plVal = data; return vt; } CComVariant vt = DeletgateGetData(item); CComPtr spData((IMyInterface*)vt.plVal);//it there any better way here???

          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