Read a compound document

  • Thread starter Thread starter Polo
  • Start date Start date
P

Polo

Hi,

We developped an application that save files as a compound document.

Now we developp a new version in net and we would like to import old file
format. What is the best way. A sample or a link is welcome

Thank's in advance

Polo
 
HI,

I think that depends of the document itself, in .net you can read a binary
file so in principle you can recreate the same structure. it's up the app to
interprete the bytes properly though.

How was the document created?



cheers,
 
Hi,

The partail code below is used to generate the compound file

STDMETHODIMP CProject::SaveCompound(BSTR FileName)
{
CComPtr<IStorage> pRootStorage;
if (StgIsStorageFile(FileName) == S_OK)
{
_RTVH(StgOpenStorage(FileName, NULL, STGM_DIRECT | STGM_READWRITE |
STGM_SHARE_EXCLUSIVE, NULL, 0, &pRootStorage));
}
else
{
_RTVH(StgCreateDocfile(FileName, STGM_DIRECT | STGM_READWRITE |
STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &pRootStorage));
}
CComPtr<IPersistStorage> pPersistStorage;
_RTVH(QueryInterface(IID_IPersistStorage,
reinterpret_cast<void**>(&pPersistStorage)));
_RTVH(pPersistStorage->Save(pRootStorage, FALSE));
return S_OK;
}

HRESULT CProject::Save(IStorage* pStorage, BOOL fSameAsLoad)
{
CComPtr<IStorage> pProjectStorage;
_RTVH(pStorage->CreateStorage(OLESTR("IProject"), STGM_DIRECT |
STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0,0,
&pProjectStorage));
CComPtr<IStream> pStream;
_RTVH(pProjectStorage->CreateStream(OLESTR("Contents"), STGM_DIRECT |
STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0,0, &pStream));
CComPtr<IPersistStreamInit> pPersistStreamInit;
_RTVH(QueryInterface(IID_IPersistStreamInit,
reinterpret_cast<void**>(&pPersistStreamInit)));
_RTVH(pPersistStreamInit->Save(pStream, FALSE));
return S_OK;
}


HRESULT CProject::Save(LPSTREAM pStm, BOOL fClearDirty)
{
ULONG lWrite;
_RTVH(m_bstrVersion.WriteToStream(pStm));
_RTVH(m_bstrDescription.WriteToStream(pStm));
_RTVH(m_bstrShortDescription.WriteToStream(pStm));
_RTVH(m_bstrOwner.WriteToStream(pStm));
_RTVH(pStm->Write((void*)&m_eInterpolationMethod,
sizeof(m_eInterpolationMethod), &lWrite));
_RTVF(lWrite != sizeof(m_eInterpolationMethod));
....
}
 
Hi,


You will have to reverse engineer it, if you have the source code you can
follow it and see how it saves the pieces, you will have to duplicate it in
..NET , most probably you will have to recreate the same struct currently
being used.

I cant think of another solution less cumbersome :(

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 
Back
Top