ATL newbie creating VB like collection question 
Author Message
 ATL newbie creating VB like collection question

Hi everybody,
I hope this is the right place to post this. I'm using STL and ATL to create
a VB like collection in CV.
I having a couple of problems:
1. The enumerator doesn't appear to be working properly.
2. I'm not sure I getting the object into the collection correctly.

My add method looks like this:

STDMETHODIMP CCollection::Add(VARIANT *pv)
{
 CComObject<CObj>* pObj;
 LPDISPATCH lpDisp = NULL;

 HRESULT hRes =
   CComObject<CObj>::CreateInstance(&pObj);

 _ASSERTE(SUCCEEDED(hRes));

 // set arbitrary values
 pObj->vpp = (void**)(pv);

 // get IDispatch pointer
 pObj->QueryInterface(IID_IDispatch, (void**)&lpDisp);
 _ASSERTE(lpDisp);

 // create a variant and add it to the
 CComVariant var;
 var.vt = VT_DISPATCH;
 var.pdispVal = lpDisp;
 m_Vector.push_back(var);

 return S_OK;

Quote:
}

My _NewEnum looks like this:

STDMETHODIMP CCollection::get__NewEnum(IUnknown ** ppUnk)
{
 if (NULL == ppUnk) return E_POINTER;

 *ppUnk = NULL;

 typedef CComEnumOnSTL<IEnumVARIANT,
                    &IID_IEnumVARIANT,
        VARIANT,
                          _Copy<VARIANT>,
        std::vector<CComVariant> > VarVarEnum;

 return CreateSTLEnumerator<VarVarEnum>(ppUnk,
static_cast<ICollection*>(this), m_Vector);

Quote:
}

and my Item property looks like this:

STDMETHODIMP CCollection::get_Item(long Index, IUnknown **pVal)
{
 if (NULL == pVal) return E_POINTER;

 // use 1-based index, VB like
 if ((Index < 1) || (Index > m_Vector.size() ))
  return E_INVALIDARG;

 VariantInit(pVal);
 pVal->vt = VT_UNKNOWN;
 pVal->punkVal = NULL;

 // Adjust to 0-based by subtracting 1.
 ::VariantCopy(pVal, &m_Vector[Index-1]);

 return S_OK;

Quote:
}

Any help would be appreciated. I'm getting the feeling that the parameters
to add and Item are wrong, but I'm not sure what it needs to look like. This
is  my very first project so please excuse my newbieness.

--
Steve Long



Sat, 11 Jan 2003 03:00:00 GMT  
 ATL newbie creating VB like collection question
Opps, my Item property looks like this not the way I pasted it before:

STDMETHODIMP CCollection::get_Item(long Index, VARIANT *pVal)
{
 if (NULL == pVal) return E_POINTER;

 // use 1-based index, VB like
 if ((Index < 1) || (Index > m_Vector.size() ))
  return E_INVALIDARG;

 VariantInit(pVal);
 pVal->vt = VT_UNKNOWN;
 pVal->punkVal = NULL;

 // Adjust to 0-based by subtracting 1.
 ::VariantCopy(pVal, &m_Vector[Index-1]);

 return S_OK;

Quote:
}



Quote:
> Hi everybody,
> I hope this is the right place to post this. I'm using STL and ATL to
create
> a VB like collection in CV.
> I having a couple of problems:
> 1. The enumerator doesn't appear to be working properly.
> 2. I'm not sure I getting the object into the collection correctly.

> My add method looks like this:

> STDMETHODIMP CCollection::Add(VARIANT *pv)
> {
>  CComObject<CObj>* pObj;
>  LPDISPATCH lpDisp = NULL;

>  HRESULT hRes =
>    CComObject<CObj>::CreateInstance(&pObj);

>  _ASSERTE(SUCCEEDED(hRes));

>  // set arbitrary values
>  pObj->vpp = (void**)(pv);

>  // get IDispatch pointer
>  pObj->QueryInterface(IID_IDispatch, (void**)&lpDisp);
>  _ASSERTE(lpDisp);

>  // create a variant and add it to the
>  CComVariant var;
>  var.vt = VT_DISPATCH;
>  var.pdispVal = lpDisp;
>  m_Vector.push_back(var);

>  return S_OK;
> }

> My _NewEnum looks like this:

> STDMETHODIMP CCollection::get__NewEnum(IUnknown ** ppUnk)
> {
>  if (NULL == ppUnk) return E_POINTER;

>  *ppUnk = NULL;

>  typedef CComEnumOnSTL<IEnumVARIANT,
>                     &IID_IEnumVARIANT,
>         VARIANT,
>                           _Copy<VARIANT>,
>         std::vector<CComVariant> > VarVarEnum;

>  return CreateSTLEnumerator<VarVarEnum>(ppUnk,
> static_cast<ICollection*>(this), m_Vector);
> }

> and my Item property looks like this:

> STDMETHODIMP CCollection::get_Item(long Index, IUnknown **pVal)
> {
>  if (NULL == pVal) return E_POINTER;

>  // use 1-based index, VB like
>  if ((Index < 1) || (Index > m_Vector.size() ))
>   return E_INVALIDARG;

>  VariantInit(pVal);
>  pVal->vt = VT_UNKNOWN;
>  pVal->punkVal = NULL;

>  // Adjust to 0-based by subtracting 1.
>  ::VariantCopy(pVal, &m_Vector[Index-1]);

>  return S_OK;
> }

> Any help would be appreciated. I'm getting the feeling that the parameters
> to add and Item are wrong, but I'm not sure what it needs to look like.
This
> is  my very first project so please excuse my newbieness.

> --
> Steve Long




Sat, 11 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie ATL Question : Adding methods that return values to VB

2. ATL Collection for VB Use

3. Accessing a collection from a VB com server in a VC/ATL Client

4. create a VB collection object in VC

5. Creating VB For..Each compatible collections with Visual C++ 4.2

6. Looking for an easy way to create collections under ATL

7. Using VB collections in a VB DLL in VC

8. Newbie CMap collections questions

9. Newbie Question: AClass to automatically parse a web page and return a collection of links

10. Newbie: Writing an ATL object in C++ for VB late binding

11. Creating ATL object for use in VB

12. Creating ATL event server for VB clients

 

 
Powered by phpBB® Forum Software