Serializing data..

This is a mfc dialog based application.
The execution of this program starts when InitInstance() starts and ends when
InitInstance() returns. I need to make certain members(strings) of the application object(theApp) serializable. I used
DECLARE_SERIAL(CLogMasterAMApp) in the
class, and
IMPLEMENT_SERIAL(CLogMasterAMApp, CWinApp, 1) in the implementation file.
I overrode the serialize function.
I performed a test by putting msg boxes
in the storing and loading parts of the serialize function, and it appears that
the serialize function itself is not being called by the framework.
Is there something I did wrong or something I should have done?
The framework calls serialize before
InitInstance() right?
Any help would be appreciated..




cManAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bhatConnect With a Mentor Commented:
Hi

Do the following things

in application .h file

protected:
         // protected constructor used by dynamic creation
      DECLARE_DYNCREATE(CLogMasterAMApp)
Add a cfile member
CFile *m_pfile;


in application .cpp
IMPLEMENT_DYNCREATE(CLogMasterAMApp, CWinApp)

in the constructor
m_pfile = new CFile;

Map the serilize function the app class.

Add the following in the initinstance before the DoModal()

BOOL Open = pfile->Open("c:\\end.TXT", CFile :: modeRead);
if(Open){
  CArchive ar(pfile, CArchive :: store, 4096, NULL);
  CObject :: Serialize(ar);
  CLogMasterAMApp::Serialize(ar) ;
}

where end.TXT is file in to which U will be serializing the data.

In the serialize function  U can store in to this file in
If(Storing )
{
 ar << something; // where something is a member variabl in //app class
}

Hope this helps
0
 
GlennDeanCommented:
cMan:
   I do not believe the framework calls Serialize before InitInstance.  You must do an Open or Save operation.
   The only other thing I can think of is to correctly serialize an object, you must
   1.  Define a constructor with no parameters
   2.  Do not override IsSerializable
   3.  Call base-class Serialize BEFORE you try to load/retrieve data.
   Glenn
0
 
bhatCommented:

Change
BOOL Open = pfile->Open("c:\\end.TXT", CFile :: modeRead);
to
BOOL Open = pfile->Open("c:\\end.TXT", CFile :: modeWrite);

0
 
cManAuthor Commented:
hank you. your code helped me to resolve
my problem.
-Neil
0
 
bhatCommented:
U are Welcome

Bhat
0
All Courses

From novice to tech pro — start learning today.