CoderSource.net
Search
Re: Saving a string to file obtained from an Open File dialog box
Started by theDentist at 06-15-2006 11:15 AM. Topic has 3 replies.

Print Search « Previous Thread Next Thread »
   06-15-2006, 11:15 AM
theDentist is not online. Last active: 1/5/2008 4:01:46 PM theDentist

Top 10 Posts
Joined on 12-05-2005
Posts 42
Saving a string to file obtained from an Open File dialog box

Hi all,

Can anyone give me an answer to this problem.  Why is it that I cannot save to file, a string obtained using the GetPathName() function of the Open File dialog box class.  The pathway string is a member of a class in which I am serializing a stream of string variables to a binary file.  All other strings save OK, no problems, but this one string obtained from the Open Dialog box doesn't.

Any ideas??

Peter

 


   Report 
   06-18-2006, 3:38 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Saving a string to file obtained from an Open File dialog box
Hi

It looks odd :S can you paste the piece of code you are using and how do u saving the Serilized object.

Best Regards
Yasir
   Report 
   06-20-2006, 3:29 PM
theDentist is not online. Last active: 1/5/2008 4:01:46 PM theDentist

Top 10 Posts
Joined on 12-05-2005
Posts 42
Re: Saving a string to file obtained from an Open File dialog box

Hi Yasir,

When I use the CFile::Read and CFile::Write functions on an open CFile object it works fine, I can save the string obtained from the open dialog box to a text file  However when I write a class that have several strings as member variables, then serialize them into a CArchive object by overriding the Serialize function like the following:

void CMyClass::Serialize(CArchive& ar) 
{
  CObject::Serialize(ar);
     if(ar.IsStoring())
   ar << StringOne << StringTwo << StringThree<< StringFour;

  else
   ar >> StringOne>> StringTwo >> StringThree >> StringFour;
}

Where the strings are the member variables of CMyClass. I then save the CArchive variable ar to file as follows

if(theFile.Open("hostDetails.dat",

CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite))
 {
  CArchive ar(&theFile,CArchive::store);
  Serialize(ar);
  ar.Close();
  theFile.Close();
 }

where theFile is a declared CFile object.  This has worked fine for me many times, and I use it for CObList linked lists as well.  But if one of those strings is from an open dialog box obtained with GetPathName() it won't save no matter what I do.  Why??

Best regards,

 

Peter


   Report 
   06-25-2006, 2:55 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Saving a string to file obtained from an Open File dialog box
its quiet surprising. I have not yet got answer what is the cause. I will look into this. did you find any thing what may be the cause then let me know.

Best Regards
Yasir
   Report 
Codersource.Net » Programming » MFC Programming » Re: Saving a string to file obtained from an Open File dialog box

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us