Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
developer
active.documents
automation
binary.file_format
clipboard.dde
com.add_ins
hosting.controls
internet_other
office.sdks
officedev
officedev.other
outlook.forms
outlook.vba
smarttags
vba
web.components
  
 
date: Wed, 3 Aug 2005 09:57:13 -0700,    group: microsoft.public.office.developer.active.documents        back       


How to save to an embedded OLE server's Storage   
Hello, 

I am writing an embeded ole server that I want to save some state when the 
container saves it's document.  I have been testing in Word 2003, and my 
implementation of IPersistStorage::Save gets called fine.   I make all of my 
modifications to the storage (replace stream, write stream) and then return a 
succesful HRESULT.

I have verified that all operations succeed, but upon inspection of the word 
file with DFVIEW, I can see that my changes have not been applied.

I have tried calling IStorage::Commit even though the storage I am 
manipulating probably isn't the root storage. And upon inspecting the call 
stack with OS symbols installed, I can tell that word calls OleSave to save 
my object, and that this function should commit the storage upon success.

Right now I am at a loss and was wondering if there was anything else I 
should do in order to get my changes committed to the document.  Thanks.

Steven

Code Sample Follows:
HRESULT COLEserver::IPersistStorage_SaveCompanion(IStorage* pStorage, BOOL 
/*bSameAsLoad*/)
{
    assert(pStorage != NULL);
    IStreamPtr spStream;
    HRESULT hr = E_FAIL;
    try
    {

        CComBSTR bstrViewerParams;
		// code to get string from viewer omitted

        // Create the stream we will save to.
        if (SUCCEEDED(hr))
        {
            hr = pStorage->CreateStream(VIEW_STREAM_NAME, 
                STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
                0, 0, &spStream);
        }

        if (SUCCEEDED(hr) && (spStream != NULL))
        {

            DWORD szVer = sizeof(VIEW_STREAM_VER);
            // Remember the version, just in case this changes in the future
            hr = spStream->Write(&VIEW_STREAM_VER, szVer, &szVer);
            assert(szVer == sizeof(VIEW_STREAM_VER));

            if (SUCCEEDED(hr))
            {
                hr = bstrViewerParams.WriteToStream(spStream);
            }

            if (SUCCEEDED(hr))
            {
                pStorage->Commit(STGC_DEFAULT);
                m_bViewChanged = false;
            }
        }
    }
    catch (_com_error e)
    {
        hr = e.Error();
        ATLTRACE(_T("Error when trying to save view information to stream: 
0x%08x"), hr);
    }

    return hr;
}



-- 
Steven Velez
Hanna Strategies
Sr. Software Engineer
date: Wed, 3 Aug 2005 09:57:13 -0700   author:   Steven Velez am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us