Solved

Serialization

Posted on 2001-09-02
6
644 Views
Last Modified: 2013-11-20
Hi,
I use CMemFile and CArchive
First store in ar and save buffer from file in Registry key
What I store is CObArray
The object is:
class Sites
{
private:
CString first,second;
public:
CString GetFirst();
CString GetSecong();
...
}
Here is my OnCreate() where I whant to read stored data and init CListBox

const INT nSIZE = 4096;
HKEY hKey;
DWORD dwType;
DWORD dwData  = nSIZE;
BYTE* bData   = (BYTE*)::calloc(nSIZE, sizeof(TCHAR));
ASSERT(bData);

     if(ERROR_SUCCESS !=
   
     ::RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Pltodorov\\ReplCheck\\",0,KEY_ALL_ACCESS,&hKey))
   
    MessageBox("Error Open");



const LONG retValue = ::RegQueryValueEx(hKey, "proba", NULL, &dwType,bData, &dwData);
     
     
if(retValue == ERROR_SUCCESS && REG_BINARY == dwType)
     {

  // Load Read values in file
  CMemFile file(bData, nSIZE);
 
  //Attach file to archive
  CArchive ar(&file, CArchive::load);

  //Load "object"
  object.Serialize(ar);

  ar.Close();
  file.Close();

     }

// Loop and load elements to List box
     if(object.GetSize())
     {
     
     for(int i=0;i < object.GetSize();i++)
          {
     
          Sites*     pSite=(Sites*)object[i];
               
          CRuntimeClass*     pRt=pSite->GetRuntimeClass();
         
          pRt->m_nObjectSize;


          if(pSite->IsKindOf(RUNTIME_CLASS(Sites))) MessageBox("It Is");
         
          CListBox* pList=(CListBox*)dlgbar.GetDlgItem(IDC_LIST);
         
          pList->AddString(pSite->GetFirst());
          }
My problem is that pRt->m_nObjectSize;
in not 0 but string stay empty
0
Comment
Question by:plamtod
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6448961
what is the full definition of Sites look like?

CObList::Serialize requires that you provide friend operators for << and >> for non CObject classes (eg CString)


friend CArchive& AFXAPI operator<<(CArchive& ar, const Sites& sites)
{
  ar << sites.first;
  ar << sites.second;
}

friend CArchive& AFXAPI operator>>(CArchive& ar, Sites& sites)
{
  ar >> sites.first;
  ar >> sites.second;
}



0
 

Author Comment

by:plamtod
ID: 6448977
class Sites : public CObject  
{
public:
     void SetSecond(CString nSecond);
     CString GetSecond();
     CString first;
     void SetFirst(CString nFirst);
     CString GetFirst();
     Sites();
     virtual ~Sites();

private:
     CString second;
//     CString first;

     DECLARE_SERIAL(Sites)//!!!!!!!
};

It's possible
CObArray object;
object.Serializa(ar);
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6449165
yes but whan you do DECLARE_SERIAL you will see that MFC defines that you require the above >> friend operator (afx.h) - the above operators I mentioned above - should work (Maybe with a few mods) but the essence is there

> It's possible

it is working now ? or it compiles ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:plamtod
ID: 6449878
I use the idea from
http://camis.kaist.ac.kr/~mkshin/msvc_source/misc/stringlist_to_reg.shtml

Should I predefine <<(>>).
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 50 total points
ID: 6449967
I see - but if you look in mfc/src/list_s.cpp you will see that CStringList::Serialize(CArchive& ar) understands that it is dealing with CStrings and will therefore serialize them correctly - what I am saying is that MFC does not undestand how to serialize Sites and will need help (from you)
0
 

Author Comment

by:plamtod
ID: 6450037
Thanks a lot.
I wasn't overload Serialize for Sites class
Now O.K.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
only14 challenge 19 68
EvenOdd challenge 10 88
Use of condition with 'serial' in ansible 2 49
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now