Saving List Items to Disk

Posted on 2003-11-04
Last Modified: 2013-11-20
I have the following code in my project:

void CIRCServerConnector::SaveServerList(void)
      CFile fileServLst("servlist.dat", CFile::modeCreate | CFile::modeReadWrite);

      CArchive arStore(&fileServLst, CArchive::store);

      POSITION aPos = m_listServers.GetHeadPosition();
      CIRCServer* temp;

            temp = m_listServers.GetNext(aPos);

It is supposed to go through a CTypedPtrList and save each item to by one. Right now...I am getting a dialog box that pops up and says "An unsupported operation was attempted"...never seen that before. Can anyone help tell me what is going on here?
Question by:SGyves
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 23

Expert Comment

by:Roshan Davis
ID: 9684129
Attempting to retrieve a CIRCServer* on any other object will result in a system error (the utterly enigmatic "An unsupported operation was attempted"), MSDN documented something like this.

can u tell me, in which point of code that error comes..?

Rosh :)

Accepted Solution

Priyesh earned 400 total points
ID: 9684172
Just a reminder list, you might be already doing this.

class CIRCServer : public CObject//derive from cobject to
   void Serialize(CArchive& ar) ;
   CString szName ;

IMPLEMENT_SERIAL(CIRCServer, CObject, 1)//needed to enable serialization

void CIRCServer::Serialize(CArchive& ar)//Called by WriteObject
     ar >> szName ;
     ar << szName ;  

And, a try - catch to catch CArchiveException or others to get any further details abt the error

Author Comment

ID: 9684336 happens right on the WriteObject line:


that one.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9684340
OMG...I think I forgot the IMPLEMENT_SERIAL and DECLARE_SERIAL statements.   (Slapping my head)


Author Comment

ID: 9684342
A long day indeed...that was it.

Author Comment

ID: 9684585
Hey...what is the best way to read these back from disk untill there are no can I check for EOF??

Expert Comment

ID: 9684799
Would this work for you??

      CIRCServer clsServer ;
      clsServer.szName = "IRCServer" ;

      CTypedPtrArray<CObArray, CIRCServer*> clsArraySave, clsArrayLoad ;
      clsArraySave.Add(&clsServer) ;

            CFile clsFile("c:\\ircobjects.dat", CFile::modeCreate|CFile::modeWrite) ;
            CArchive ar(&clsFile, CArchive::store) ;
            clsArraySave.Serialize(ar) ;

            CFile clsFile("c:\\ircobjects.dat", CFile::modeRead) ;
            CArchive ar(&clsFile, CArchive::load) ;
            clsArrayLoad.Serialize(ar) ;

            CIRCServer* pServer = clsArrayLoad.GetAt(0) ;
            TRACE("Name = %s\n", pServer->szName) ;


Author Comment

ID: 9687910
Yes...I believe that will work. As I understand...the serialize for the CTypedPtrList serializes all elemnts into the file. Cool.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question