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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. Arrays of IUnknown..

Arrays of IUnknown..

Scheduled Pinned Locked Moved COM
c++csharpcomsysadmindata-structures
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.
  • I Offline
    I Offline
    ICBM
    wrote on last edited by
    #1

    Hello all What I am trying to do is implement a function in an ATL COM server that returns an array of objects. I need to be able to use these objects from VB. My searches on the net turned up lots of references to using SAFEARRAY(VARIANT), but very little sample code. Ideally, I'd love a link to some code that declares a method like GetObjects([in,out] SAFEARRAY(VARIANT) *ppObjects) and shows both the implementation in C++ (including creating and populating the SAFEARRAY with IUnknown-derived object pointers) and some calling code, either in VB or C#. Thanks all Ian

    V F 2 Replies Last reply
    0
    • I ICBM

      Hello all What I am trying to do is implement a function in an ATL COM server that returns an array of objects. I need to be able to use these objects from VB. My searches on the net turned up lots of references to using SAFEARRAY(VARIANT), but very little sample code. Ideally, I'd love a link to some code that declares a method like GetObjects([in,out] SAFEARRAY(VARIANT) *ppObjects) and shows both the implementation in C++ (including creating and populating the SAFEARRAY with IUnknown-derived object pointers) and some calling code, either in VB or C#. Thanks all Ian

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      There are some good examples here at CodeProject. Look under the beginner section. http://www.codeproject.com/com/ Kuphryn

      1 Reply Last reply
      0
      • I ICBM

        Hello all What I am trying to do is implement a function in an ATL COM server that returns an array of objects. I need to be able to use these objects from VB. My searches on the net turned up lots of references to using SAFEARRAY(VARIANT), but very little sample code. Ideally, I'd love a link to some code that declares a method like GetObjects([in,out] SAFEARRAY(VARIANT) *ppObjects) and shows both the implementation in C++ (including creating and populating the SAFEARRAY with IUnknown-derived object pointers) and some calling code, either in VB or C#. Thanks all Ian

        F Offline
        F Offline
        first_sandy
        wrote on last edited by
        #3

        Hi Ian, You can create a safe array of variants and then put the array in the variant and pass to the client. Like : SAFEARRAY *pSA =NULL; SAFEARRAYBOUND sabound; sabound.cElements = nCount; //Array size. sabound.lLbound = 0; pSA = SafeArrayCreate(VT_VARIANT, 1, sabound); long nIterator = 0; //in a loop put the values. hr = SafeArrayPutElement(pSA, nIterator, (void *)&vaPutValue); VARIANT vaResult; VariantInit(&vaResult); V_VT(&vaResult) = VT_ARRAY | VT_VARIANT; V_ARRAY(&vaResult) = pSA; return vaResult; At client side, you can write it like: Dim vaDocList as Variant vaDocList = m_pClass.GetArray() 'm_pClass is the reference to co-class. get bounds like nUBound = UBound(vaDocList) nLBound = LBound(vaDocList) in a loop get values in the variables as per ur requirement. i feel it will help you. :-O sandy Last night i realized, i was seeing a dream in my dream.

        I 1 Reply Last reply
        0
        • F first_sandy

          Hi Ian, You can create a safe array of variants and then put the array in the variant and pass to the client. Like : SAFEARRAY *pSA =NULL; SAFEARRAYBOUND sabound; sabound.cElements = nCount; //Array size. sabound.lLbound = 0; pSA = SafeArrayCreate(VT_VARIANT, 1, sabound); long nIterator = 0; //in a loop put the values. hr = SafeArrayPutElement(pSA, nIterator, (void *)&vaPutValue); VARIANT vaResult; VariantInit(&vaResult); V_VT(&vaResult) = VT_ARRAY | VT_VARIANT; V_ARRAY(&vaResult) = pSA; return vaResult; At client side, you can write it like: Dim vaDocList as Variant vaDocList = m_pClass.GetArray() 'm_pClass is the reference to co-class. get bounds like nUBound = UBound(vaDocList) nLBound = LBound(vaDocList) in a loop get values in the variables as per ur requirement. i feel it will help you. :-O sandy Last night i realized, i was seeing a dream in my dream.

          I Offline
          I Offline
          ICBM
          wrote on last edited by
          #4

          Thanks very much for that, just what I was after :-)

          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