Help with ATL COM code for a kind of collection !
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;
}