Arrays of IUnknown..
-
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
-
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
There are some good examples here at CodeProject. Look under the beginner section. http://www.codeproject.com/com/ Kuphryn
-
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
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.
-
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.