473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trouble upgrading some C++ code from v6 to 2003

OK, I'm finally getting our organization to upgrade from v6, and the first
project I try to recompile I run into hairy problems. We've used this ATL COM
collection class for years. It looks like maybe I could write a simpler one
with newer features in ATL, but this one works fine if only it would compile.
Any suggestions?

COMVectorCollection.h:

#include <vector>

////////////////////////////////////////////////////////////////////////
/////
// CComCollect
//
// icontainer: The interface for the container
// container_iid: The IID for the container interface
// libid: The GUID for the library
// container: The implementation class for the container
// icontained: The interface for the contained interface
// contained_iid: The IID for the contained interface
//
// Usage:
// Derive your collection class from this and CComObjectRootEx. Since this
template class
// inherits from CComCoClass, IDispatchImpl, and ISupportErrorInfo, you
should not inherit
// from those in your concrete class. Here's an example declaration:
//
// class ATL_NO_VTABLE CSomeCollection :
// public CComObjectRootEx<CComSingleThreadModel>,
// public CComCollect<ISomeCollection, &IID_ISomeCollection,&LIBID_SomeLib,
CSomeItem,
// &CLSID_SomeCollection, ISomeInterface,
&IID_ISomeInterface>
//
// If all you need are the standard Add, Remove, Item, get_Count, and
get__NewEnum methods,
// then you do not need to provide any other implementation. Just make sure
you declare
// the interface for your collection class in an IDL file. Here's the
example for the
// above declaration:
//
// interface ISomeCollection : IDispatch
// {
// [propget, id(1)] HRESULT Count([out, retval] long *pVal);
// [id(2)] HRESULT Add([in] ISPCChart* inItem);
// [id(3)] HRESULT Remove([in] long inIndex);
// [propget, id(DISPID_VALUE)] HRESULT Item([in] long inIndex,
// [out, retval] ISPCChart**
outChart);
// [propget, id(DISPID_NEWENUM)] HRESULT _NewEnum([out,
retval]LPUNKNOWN *pVal);
// };
//
// You are free to add additional accessor/builder methods (note that the
collection
// implementation is exposed. Just declare it in your header and the IDL
and provide an
// implementation.
//

template <class icontainer, const IID* container_iid, const GUID* libid,
class container,
const CLSID* container_clsid, class icontained, const IID*
contained_iid>
class ATL_NO_VTABLE CComCollect :
public CComCoClass<container, container_clsid>,
public IDispatchImpl<icontainer, container_iid, libid>,
public ISupportErrorInfo
{
public:
CComCollect() {}
// ISPCChartSpecs
public:
STDMETHOD(RemoveAll)();
STDMETHOD(Add)(/*[in]*/ icontained* inItem);
STDMETHOD(get__NewEnum)(/*[out, retval]*/ LPUNKNOWN *pVal);
STDMETHOD(get_Item)(/*[in]*/ long inIndex, /*[out, retval]*/
icontained** outChart);
STDMETHOD(get_Count)(/*[out, retval]*/ long *pVal);
STDMETHOD(Remove)(/*[in]*/ long inIndex);

// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// Helper functions
typedef std::vector<CComVariant> collection;
typedef collection::iterator iterator;
iterator begin();
iterator end();

protected:
collection mCollect;
bool mDirty;
};

template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>

STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained, contained_iid>
::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] = { container_iid, };
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}

template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained,
const IID* contained_iid>
typename CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained, contained_iid>::iterator
typename CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained, contained_iid>::begin()
{
return mCollect.begin();
}

template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
typename CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained, contained_iid>::iterator
typename CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained, contained_iid>::end()
{
return mCollect.end();
}

// Returns the number of elements in the collection
template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::get_Count(long * pVal)
{
// Make sure we didn't get a null pointer passed in
if (!pVal)
return E_POINTER;

// Get the size from the collection
*pVal = mCollect.size();

return S_OK;
}

// Returns a single item corresponding to the index
template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::get_Item(long inIndex, icontained** outContained)
{
// Make sure we didn't get a null pointer passed in
if (!outContained)
return E_POINTER;

// Make sure the index is within range (index is 1-based)
if (inIndex < 1 || inIndex > mCollect.size())
return E_INVALIDARG;

// Get the variant out of the collection
CComVariant& var = mCollect[inIndex-1];

// Make sure we've got an element
HRESULT hr = var.pdispVal->QueryInterface(*contained_iid,
(void**)outContained);
if (FAILED(hr))
return E_UNEXPECTED;

return S_OK;
}

template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::get__NewEnum(LPUNKNOWN * pVal)
{
// Make sure we didn't get a null pointer passed in
if (!pVal)
return E_POINTER;

*pVal = 0;

// Create the enumeration object
typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT,
VARIANT, _Copy<VARIANT> > > enumVar;
enumVar* pEnum = new enumVar;
if (!pEnum)
return E_OUTOFMEMORY;

// Initialize with the chart collection iterators
HRESULT hr = pEnum->Init(mCollect.begin(), mCollect.end(),
NULL,AtlFlagCopy);
if (SUCCEEDED(hr))
hr = pEnum->QueryInterface(IID_IEnumVARIANT, (void**)pVal);
if (FAILED(hr))
delete pEnum;
return hr;
}

template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::Add(icontained* inItem)
{
HRESULT hr = S_OK;
icontained* pContained;

// Make sure we've got an element
hr = inItem->QueryInterface(*contained_iid, (void **)&pContained);
if (FAILED(hr))
return E_UNEXPECTED;

// Add the variant (dispatch) to the collection
mDirty = TRUE;
mCollect.push_back(CComVariant(inItem));
pContained->Release();

return hr;
}

// Removes an item at an integer index
template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::Remove(long inIndex)
{
HRESULT hr = S_OK;

// Make sure the index is within range (index is 1-based)
if (inIndex < 1 || inIndex > mCollect.size())
return E_INVALIDARG;

mDirty = TRUE;
mCollect.erase(mCollect.begin() + inIndex - 1);

return hr;
}

/////////////////////////////////////////////////////////////
//
// Remove all elements from the collection
//
template <class icontainer, const IID* container_iid, const GUID* libid,
class container, const CLSID* container_clsid, class icontained, const IID*
contained_iid>
STDMETHODIMP CComCollect<icontainer, container_iid, libid, container,
container_clsid, icontained,
contained_iid>::RemoveAll()
{
mCollect.erase(mCollect.begin(), mCollect.end());
return S_OK;
}
Nov 17 '05 #1
0 1078

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike Owen | last post by:
Hi, I have just used the import Wizard to import a VS 2003 app to VS 2005. I have a lot of work to do to enable it to compile successfully with all the errors and warnings it gave me, but as a...
13
by: Noesis Strategy | last post by:
When I ordered my new laptop, Sony didn't offer Access 2003 in its bundles. Recently, I have begun to design Access databases using an copy of Access 2002 from my previous laptop. It works fine,...
11
by: Aidan Tobin | last post by:
Hi, I have to upgrade a number of databases from Access 2.0, Access 97 and Access 2000 to work in Office 2003. These databases contain a number of Forms coded with VBA as well as a number of...
4
by: james | last post by:
I upgraded my 2002 project to 2003 and I am getting several of there errors on my forms xxxForm.resx Resource transformation for file 'xxxForm.resx' failed. Possible Version mismatch. Type...
4
by: Spurry Moses | last post by:
I know it's in Beta 2, but I can't report any good experiences with upgrading a project form 2003 to 2005. I tried to upgrade a 2003 project to C# Express 2005. My application has hardly...
1
by: Ray Wampler | last post by:
According to the information on the Microsoft web site, code written in VB.NET 2002 can simply be recompiled using VS.NET 2003. However, I have found that code which compiles cleanly in VS.Net...
15
by: Asaf | last post by:
Hi, I have received a source code project written in C++ VS.NET 2003 on .NET 1.1 that compiles without a problem. I have opened this source code in VS.NET 2005 and the Log wizard says that...
0
by: fripper | last post by:
I have a VB .Net 2003 program that I am upgrading to VB 2005. It includes a data structure that defines an object containing a number of fixed length (stirng) fields. Somehting like the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.