Click here to Skip to main content
15,921,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Class prototype? Pin
Swinefeaster1-Feb-02 14:14
Swinefeaster1-Feb-02 14:14 
GeneralRe: Class prototype? Pin
Tim Smith1-Feb-02 14:40
Tim Smith1-Feb-02 14:40 
GeneralRe: Class prototype? Pin
Tantalus1-Feb-02 16:30
Tantalus1-Feb-02 16:30 
GeneralRe: Class prototype? Pin
Swinefeaster1-Feb-02 16:37
Swinefeaster1-Feb-02 16:37 
GeneralSort of Serialization Pin
1-Feb-02 14:00
suss1-Feb-02 14:00 
GeneralRe: Sort of Serialization Pin
Swinefeaster1-Feb-02 14:03
Swinefeaster1-Feb-02 14:03 
GeneralRe: Sort of Serialization Pin
1-Feb-02 14:44
suss1-Feb-02 14:44 
GeneralRe: Sort of Serialization Pin
Matt Gullett1-Feb-02 14:52
Matt Gullett1-Feb-02 14:52 
Basically, CArchive just uses a CFile object as its internal file access class. The Serialize function for your object is passed a CArchive automatically by the framework, but you can do it manually also.

----------------------------------------
to serialize your data to disk:
----------------------------------------
CFile fp;

fp.Open(somefilename,CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive);

CArchive ar(&fp, CArchive::store);

obj.Serialize(ar);

ar.Close();

fp.Close();

----------------------------------------
to load data from disk
----------------------------------------
CFile fp;

fp.Open(somefilename,CFile::modeRead | CFile::shareExclusive);

CArchive ar(&fp, CArchive::load);

obj.Serialize(ar);

ar.Close();

fp.Close();

----------------------------------
to automatically determine a file name
----------------------------------
Often, what I do is to save the file in the same path as the EXE, but I use the users computer name and user-name as the file name. If I want the user to be able to log in from different computers, I just use their user name.

char szAppPath[2000];
char szDrive[200];
char szDir[200];
char szComputer[2000];
char szUser[2000];
DWORD dwTempSize = 0;
CString strFileName;

memset(szAppPath, 0, 2000);
memset(szDrive, 0, 200);
memset(szDir, 0, 200);
memset(szComputer, 0, 2000);
memset(szUser, 0, 2000);

::GetModuleFileName(AfxGetInstanceHandle(), szAppPath);
_splitpath(szAppPath, szDrive, szDir, NULL, NULL);

dwTempSize = 2000;
::GetUserName(szUser, &dwTempSize);
dwTempSize = 2000;
::GetComputerName(szComputer, &dwTempSize);

strFileName = szDrive;
strFileName += szDir;
strFileName += szComputer;
strFileName += "-";
strFileName += szUser;
strFileName += ".dat";
---------------------------------------


PS. I wrote the above code from memory so there might be some typos, etc.

Matt Gullett
GeneralCMutex Pin
Cathy1-Feb-02 13:55
Cathy1-Feb-02 13:55 
GeneralRe: CMutex Pin
Rick York1-Feb-02 18:03
mveRick York1-Feb-02 18:03 
GeneralRe: CMutex Pin
Cathy1-Feb-02 20:39
Cathy1-Feb-02 20:39 
GeneralRe: CMutex Pin
Rick York1-Feb-02 21:08
mveRick York1-Feb-02 21:08 
GeneralRe: CMutex Pin
Cathy2-Feb-02 5:13
Cathy2-Feb-02 5:13 
GeneralWTF Pin
Stephen Caldwell1-Feb-02 13:02
Stephen Caldwell1-Feb-02 13:02 
GeneralRe: WTF Pin
Swinefeaster1-Feb-02 14:01
Swinefeaster1-Feb-02 14:01 
GeneralRe: WTF Pin
Sprudling1-Feb-02 14:03
Sprudling1-Feb-02 14:03 
GeneralRe: WTF Pin
Stephen Caldwell1-Feb-02 14:27
Stephen Caldwell1-Feb-02 14:27 
GeneralRe: WTF Pin
Tim Smith1-Feb-02 14:32
Tim Smith1-Feb-02 14:32 
GeneralCapturing the contents of another window... Pin
Peter Weyzen1-Feb-02 12:37
Peter Weyzen1-Feb-02 12:37 
GeneralRe: Capturing the contents of another window... Pin
Stephen Caldwell1-Feb-02 13:22
Stephen Caldwell1-Feb-02 13:22 
Generalmany functions to just one Pin
Steve L.1-Feb-02 11:34
Steve L.1-Feb-02 11:34 
GeneralRe: many functions to just one Pin
Ravi Bhavnani1-Feb-02 11:54
professionalRavi Bhavnani1-Feb-02 11:54 
GeneralExtended Stored Procedures Pin
RK_20001-Feb-02 9:27
RK_20001-Feb-02 9:27 
GeneralRe: further to my question Pin
RK_20001-Feb-02 11:44
RK_20001-Feb-02 11:44 
GeneralNew version of CButtonSSL Pin
Derek Lakin1-Feb-02 9:14
Derek Lakin1-Feb-02 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.