Solved

Saving List Items to Disk

Posted on 2003-11-04
8
213 Views
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;

      while(aPos)
      {
            temp = m_listServers.GetNext(aPos);
            arStore.WriteObject(temp);
      }
      arStore.Close();
}

It is supposed to go through a CTypedPtrList and save each item to disk..one 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?
0
Comment
Question by:SGyves
  • 5
  • 2
8 Comments
 
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 :)
0
 
LVL 9

Accepted Solution

by:
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
{
  DECLARE_SERIAL(CIRCServer)
public:
   void Serialize(CArchive& ar) ;
public:
   CString szName ;
};

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

void CIRCServer::Serialize(CArchive& ar)//Called by WriteObject
{
   if(ar.IsLoading())
     ar >> szName ;
   else
     ar << szName ;  
}

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

Author Comment

by:SGyves
ID: 9684336
Rosh...it happens right on the WriteObject line:

arStore.WriteObject(temp);


that one.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

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

0
 

Author Comment

by:SGyves
ID: 9684342
A long day indeed...that was it.
0
 

Author Comment

by:SGyves
ID: 9684585
Hey...what is the best way to read these back from disk untill there are no more....meaning...how can I check for EOF??
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 9684799
Would this work for you??

      CIRCServer clsServer ;
      clsServer.szName = "IRCServer" ;

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

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


//Read
      {
            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) ;
      }

0
 

Author Comment

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

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 114
while loop over for loop 7 115
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 866
unix example issues 18 99
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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