Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Serialization

Could someone tell me what is wrong with the following code. I am getting errors when I try to load prefs. Also...it doesn't look like they are writing correctly either.


m_profIRCProfile is a Pointer to a CUserProfile...

void CGoIRCApp::LoadPrefs(void)
{
      CFileStatus fs;
      if(CFile::GetStatus("userprefs.dat", fs))
      {
        CFile prefFile("userprefs.dat", CArchive::load);
            CArchive arLoad(&prefFile, CArchive::load);

            CUserProfile* ptrProf = (CUserProfile*) arLoad.ReadObject(RUNTIME_CLASS(CUserProfile));
            m_profIRCProfile = new CUserProfile(ptrProf);
      }
}

void CGoIRCApp::StorePrefs(void)
{
      CFile myFile("userprefs.dat", CFile::modeCreate | CFile::modeReadWrite);

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

      arStore.WriteObject(m_profIRCProfile);

      arStore.Close();
}

Serialize is not getting called at all. I have DECLARE_SERIAL in the .h and IMPLEMENT_SERIAL in the .cpp. What is going on?

0
SGyves
Asked:
SGyves
  • 2
1 Solution
 
_nn_Commented:
>>       CFile prefFile("userprefs.dat", CArchive::load);

Why are you using CArchive::load here ? Shouldn't it be some CFile:: flag like CFile::modeRead ?
0
 
SGyvesAuthor Commented:
(Slaps head) Ahhh...much better.....Hhehehhehe. THanks for the sanity check.
0
 
_nn_Commented:
>> Hhehehhehe. THanks for the sanity check.

Welcome :)

>> (Slaps head)

Have a break ;) Had to fight with many of those myself in the past, I know what it is ;)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now