473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

COMVectorCollec tion.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 CComObjectRootE x. Since this
template class
// inherits from CComCoClass, IDispatchImpl, and ISupportErrorIn fo, you
should not inherit
// from those in your concrete class. Here's an example declaration:
//
// class ATL_NO_VTABLE CSomeCollection :
// public CComObjectRootE x<CComSingleThr eadModel>,
// public CComCollect<ISo meCollection, &IID_ISomeColle ction,&LIBID_So meLib,
CSomeItem,
// &CLSID_SomeColl ection, ISomeInterface,
&IID_ISomeInter face>
//
// 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_NEWEN UM)] 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<con tainer, container_clsid >,
public IDispatchImpl<i container, container_iid, libid>,
public ISupportErrorIn fo
{
public:
CComCollect() {}
// ISPCChartSpecs
public:
STDMETHOD(Remov eAll)();
STDMETHOD(Add)(/*[in]*/ icontained* inItem);
STDMETHOD(get__ NewEnum)(/*[out, retval]*/ LPUNKNOWN *pVal);
STDMETHOD(get_I tem)(/*[in]*/ long inIndex, /*[out, retval]*/
icontained** outChart);
STDMETHOD(get_C ount)(/*[out, retval]*/ long *pVal);
STDMETHOD(Remov e)(/*[in]*/ long inIndex);

// ISupportsErrorI nfo
STDMETHOD(Inter faceSupportsErr orInfo)(REFIID riid);

// Helper functions
typedef std::vector<CCo mVariant> collection;
typedef collection::ite rator 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<ico ntainer, container_iid, libid, container,
container_clsid , icontained, contained_iid>
::InterfaceSupp ortsErrorInfo(R EFIID riid)
{
static const IID* arr[] = { container_iid, };
for (int i=0;i<sizeof(ar r)/sizeof(arr[0]);i++)
{
if (InlineIsEqualG UID(*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<ico ntainer, container_iid, libid, container,
container_clsid , icontained, contained_iid>: :iterator
typename CComCollect<ico ntainer, 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<ico ntainer, container_iid, libid, container,
container_clsid , icontained, contained_iid>: :iterator
typename CComCollect<ico ntainer, 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<ico ntainer, 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<ico ntainer, 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**)outCont ained);
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<ico ntainer, container_iid, libid, container,
container_clsid , icontained,
contained_iid>: :get__NewEnum(L PUNKNOWN * 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<CCom Enum<IEnumVARIA NT, &IID_IEnumVARIA NT,
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,AtlFlagCop y);
if (SUCCEEDED(hr))
hr = pEnum->QueryInterface (IID_IEnumVARIA NT, (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<ico ntainer, 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_b ack(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<ico ntainer, 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<ico ntainer, container_iid, libid, container,
container_clsid , icontained,
contained_iid>: :RemoveAll()
{
mCollect.erase( mCollect.begin( ), mCollect.end()) ;
return S_OK;
}
Nov 17 '05 #1
0 1086

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

Similar topics

5
512
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 starting point the compiler can no longer find the function as at the bottom of this posting, that was in the Global.asax.vb file. All the function does is give an easy / quick way of getting the application
13
2635
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, but I would like to have all the office apps on the same version. So I have a few questions: 1) Is the file format the same as 2002? Can 2002 users read 2003 files? 2) What are the major reasons for upgrading to 2002 ?
11
1919
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 Queries/Macros. The Microsoft web site says that Office 2003 will open databases created in these versions. However i have in the past upgraded databases from access 2.0 to 97
4
1793
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 System.Globalization.DateTimeFormatInfo has 38 members, number of members deserialized is 35. Now, when I open the .resx files I do not find any DateTimeFOrmatInfo members in the XML or in the code.
4
1544
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 anything, as I'd just started on it. It contains just a main form, and about box and a few class files. After upgrading it - which seemed to go smoothly, my main form wouldn't load. Some errors because of a custom control that I had created. I deleted...
1
1449
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 2002 gets new compile errors in VS 2003. It appears that there are new scope rules in VB.NET 2003. I get "Name not declared" errors on public functions in public modules. The errors are fixed by wrapping the module in a name space and then...
15
5062
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 Errors 0 and Warnings 0. When trying to recompile the project I have received these errors:
0
1082
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 following: (this is what the upgrade wizard created from by VB 2003 code) Private Structure DataRecord <VBFixedString(20)System.Runtime.InteropServices.MarshalAs _(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=20)> Public...
0
8413
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.