Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsI am using a COleSafeArray to transfer large quantities of data to an Excel sheet. I have coded a class to isolate the handling of Excel from the class I use it in (it will be used in more than one place ultimately)
Some code snippets.
in header
COleSafeArray m_sa;
in .cpp
//initialise safe array
DWORD dwElements[2];
dwElements[0]= iRows; //Number of rows
dwElements[1]= iCols; //Number of columns
m_sa.Create(VT_VARIANT, 2, dwElements);
....
//add a long to the safe array
long index[2];
index[0] = iRow;
index[1] = iCol;
COleVariant v((long)lItem);
m_sa.PutElement(index, v);
//OR a string LPCTSTR pszItem
long index[2];
index[0] = iRow;
index[1] = iCol;
COleVariant v(pszItem);
m_sa.PutElement(index, v);
....
//put the safe array to the sheet
m_pSheet->Range["A1:Z1"]->
//refill safe array with values for next row
m_pSheet->Range["A2:Z2"]->
and so on (there could be tens of thousands of rows in reality). The safe array is being reused, by that I mean I will call the PutElement with the same index many times.
So the question is: Do I need to cleanup the variants I put into the safearray before I put the next one into the array and if so how should the above code be modified?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: BigRatPosted on 2005-08-24 at 06:23:04ID: 14742190
Comments are available to members only. Sign up or Log in to view these comments.