Вопрос

I have a code in which CArchive is being used to read and write and file. Upon my investigation I found out that CArchive object changes its location when reading data from different parts of file. For example, if file structure is like there is header, then body and then footer. Now if someone want to read footer then CArchive reads footer only by going to specific location in file. This is done by this.

COleStreamFile stream;
//Stream is pointed to footer location.
stream.OpenStream(m_pStg, "Footer", nOpenFlags, pError);  // pStg is LPSTORAGE
CArchive ar(&stream, CArchive::load);

Now what I am interested in knowing is that at which location CArchive is going to read or write. Byte index, file location or something like that.

Это было полезно?

Решение

You cannot get the position from the CArchive object directly, but you can obtain it from the underlying stream - COleStreamFile in your case. Simply call CFile::GetPosition.

Example:

COleStreamFile stream;
//Stream is pointed to footer location.
stream.OpenStream(m_pStg, "Footer", nOpenFlags, pError);  // pStg is LPSTORAGE
CArchive ar(&stream, CArchive::load);
// Add some data.
ar << someData;

// And get the current position.
int currentPos = stream.GetPosition();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top