Click here to Skip to main content
15,906,106 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Coding time comparisons across languages Pin
jspano10-Feb-04 1:41
jspano10-Feb-04 1:41 
GeneralRe: Coding time comparisons across languages Pin
antlers10-Feb-04 4:52
antlers10-Feb-04 4:52 
Questionhow to send array through Socket Pin
Anonymous6-Feb-04 2:28
Anonymous6-Feb-04 2:28 
AnswerRe: how to send array through Socket Pin
RobJones6-Feb-04 3:46
RobJones6-Feb-04 3:46 
Questionhow to load a small Icon and a text string in a combo box ??? Pin
skpanda6-Feb-04 1:48
skpanda6-Feb-04 1:48 
AnswerRe: how to load a small Icon and a text string in a combo box ??? Pin
David Crow6-Feb-04 2:35
David Crow6-Feb-04 2:35 
GeneralMFC Pin
Member 8665696-Feb-04 1:28
Member 8665696-Feb-04 1:28 
GeneralSerialization and BSTRs Pin
Anonymous6-Feb-04 1:24
Anonymous6-Feb-04 1:24 
Hello!

I want to write an object to CArchive. My object is:

typedef struct tMyStructTag
{
  long index;
  BSTR data;
  BSTR description;
} tMyStruct;


To write data to archive I do this:

1. Open the (CFile) file in r/w mode
2. Create an archive using the open file
3. Write the data

tMyStruct myStruct; 
// Add data to myStruct
pFile->Open(...
pArchive = new CArchive(pFile, CArchive::store);
(*pArchive) << (CString)(myStruct.index);
(*pArchive) << (CString)(myStruct.data);
(*pArchive) << (CString)(myStruct.description);


Is it correct so far?

When I come to read data back, I do the same but call SeekToBegin() function for CFile class, then I read data like this:

tMyStruct myStruct; 
CString strData, strDescription;
(*pArchive) >> myStruct.index; 
(*pArchive) >> strData; 
(*pArchive) >> strDescription;
myStruct.bstrData = strData.AllocSysString();
myStruct.bstrDescription = strDescription.AllocSysString();
// ...do something with myStruct
::SysFreeString(myStruct.bstrData);
::SysFreeString(myStruct.bstrDescription);


When I do this for more than one object, I get data in wrong fields. I look at resulting file and it looks OK. I just cannot read data back correctly. Any help please?
QuestionHelp - Additional Segments Need to be defined ??? Pin
alien0016-Feb-04 1:00
alien0016-Feb-04 1:00 
AnswerRe: Help - Additional Segments Need to be defined ??? Pin
David Crow6-Feb-04 2:41
David Crow6-Feb-04 2:41 
GeneralRe: Help - Additional Segments Need to be defined ??? Pin
alien0016-Feb-04 3:33
alien0016-Feb-04 3:33 
GeneralRe: Help - Additional Segments Need to be defined ??? Pin
David Crow6-Feb-04 4:12
David Crow6-Feb-04 4:12 
GeneralRe: Help - Additional Segments Need to be defined ??? Pin
Anonymous6-Feb-04 4:17
Anonymous6-Feb-04 4:17 
GeneralRe: Help - Additional Segments Need to be defined ??? Pin
David Crow6-Feb-04 4:32
David Crow6-Feb-04 4:32 
GeneralMFC Pin
Mohannadfx6-Feb-04 0:43
Mohannadfx6-Feb-04 0:43 
GeneralRe: MFC Pin
фил6-Feb-04 0:59
фил6-Feb-04 0:59 
QuestionWhich recordset to use CRecordset or CDaoRecordset with Ms Access database? Pin
d01530306-Feb-04 0:19
sussd01530306-Feb-04 0:19 
AnswerRe: Which recordset to use CRecordset or CDaoRecordset with Ms Access database? Pin
David Crow6-Feb-04 2:49
David Crow6-Feb-04 2:49 
GeneralSetMenuItemInfo &amp; SysTray Pin
Victor19785-Feb-04 23:56
Victor19785-Feb-04 23:56 
QuestionChanging paper size - how??? Pin
Anonymous5-Feb-04 23:32
Anonymous5-Feb-04 23:32 
AnswerSorry about double post Pin
Anonymous5-Feb-04 23:36
Anonymous5-Feb-04 23:36 
AnswerRe: Changing paper size - how??? Pin
CodeBrain6-Feb-04 0:33
CodeBrain6-Feb-04 0:33 
GeneralRe: Changing paper size - how??? Pin
Anonymous7-Mar-04 21:48
Anonymous7-Mar-04 21:48 
GeneralChanging paper size Pin
Anonymous5-Feb-04 23:32
Anonymous5-Feb-04 23:32 
GeneralRe: Changing paper size Pin
Robert A. T. Káldy7-Feb-04 21:58
Robert A. T. Káldy7-Feb-04 21:58 

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.