Help with ATL COM code for a kind of collection !

R

rdc02271

Hello! I have been looking for a VB 6 collection like object (BUT
Faster) for some time now without success.
Not being a C++ programmer the thought of writting my collection/map
type COM Object didn't make my days very sunny.
Anyway I google for some code and I found something that manages to be
as slow as VB6 collection ;(

The Item method returns a variant and I wondered if returning wouldn't
be faster (I just want to return COM objects). SO i tried to make some
changes:
I'm posting the code I wrote (It compiles but I use It from VB6 it
returns something but aparently not an object?!

The goal is to create a fast (faster than VB6 collection)
map/collection to map BSTR to COM Objects.

Any help would be appreciated.
Thanks for your attention and help.
Jorge C.

std::map< CAdapt< CComBSTR >, IUnknown* > m_map;

STDMETHOD(get_ItemV3)(BSTR Key, IUnknown** ppVal)
{

HRESULT hr = S_OK;
CComBSTR var=Key;

std::map< CAdapt< CComBSTR >, IUnknown* >::iterator it;

it = m_map.find(var);
if (it == m_map.end())
return E_FAIL;


IUnknown* pElement;
// Get the item
pElement = (*it).second;

// Put the IUnknown into pItem (Also implicit AddRef())
return pElement->QueryInterface(IID_IUnknown, (void**) &ppVal);

//return S_OK;
}

STDMETHOD(AddV3)(VARIANT Key, IUnknown* pValue)
{
// Get a BSTR from the VARIANT
CComBSTR str;
HRESULT hr = VCUE::GenericCopy<BSTR, VARIANT>::copy(&str, &Key);

// If we can't convert to a string, just return
if (FAILED(hr))
return hr;

// Check whether item already exists
if (m_map.find(str) != m_map.end())
return E_FAIL; // item with this key already exists

// Add the item to the map
m_map[str] = pValue;
pValue->AddRef();
return S_OK;
}
 
H

Heinz Ozwirk

rdc02271 said:
STDMETHOD(get_ItemV3)(BSTR Key, IUnknown** ppVal) ....
return pElement->QueryInterface(IID_IUnknown, (void**) &ppVal);

This should be
return pElement->QueryInterface(IID_IUnknown, (void**) ppVal);

or better

(*ppVal) = pElement;
(*ppVal)->AddRef();
return S_OK;

For more detailed answers try microsoft.public.vc.atl.

HTH
Heinz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top