Commits

ihi  committed 7a59125

CWS-TOOLING: integrate CWS hb21_DEV300
2009-03-24 17:48:22 +0100 hbrinkm r269985 : #i100449# OutWW8TableDefinition: nSz sums the widths of columns. nTblOffset is added to the current width for every cellx.
2009-03-24 16:28:31 +0100 mav r269966 : #i100505# fix the wrapper ole-handler

  • Participants
  • Parent commits a5fdfb6

Comments (0)

Files changed (10)

File embedserv/source/embed/docholder.cxx

         m_xLayoutManager->setVisible(false);
 
     if (NULL!=m_pIOleIPSite)
+    {
+        // The following workaround should let the object be stored in case of inplace editing
+//        CComPtr< IOleClientSite > pClientSite;
+//
+//        m_pIOleIPSite->QueryInterface(
+//		        IID_IOleClientSite, (void**)&pClientSite );
+//        if ( pClientSite )
+//            pClientSite->SaveObject();
+
         m_pIOleIPSite->OnInPlaceDeactivate();
+    }
 
     if(m_pIOleIPFrame) m_pIOleIPFrame->Release(); m_pIOleIPFrame = 0;
     if(m_pIOleIPUIWindow) m_pIOleIPUIWindow->Release(); m_pIOleIPUIWindow = 0;
 	{
 		LockedEmbedDocument_Impl aDocLock = m_xOleAccess->GetEmbedDocument();
 		if ( aDocLock.GetEmbedDocument() )
+        {
             aDocLock.GetEmbedDocument()->SaveObject();
+        }
 	}
 
     return;

File embedserv/source/embed/ed_ioleobject.cxx

 	if ( m_bIsInVerbHandling )
         return OLEOBJ_S_CANNOT_DOVERB_NOW;
 
+    // an object can not handle any Verbs in Hands off mode
+    if ( m_pMasterStorage == NULL || m_pOwnStream == NULL )
+        return OLE_E_CANT_BINDTOSOURCE;
+
+
 	BooleanGuard_Impl aGuard( m_bIsInVerbHandling );
 
 	if ( iVerb == OLEIVERB_PRIMARY )
 
 STDMETHODIMP EmbedDocument_Impl::Update()
 {
-    HRESULT hr = CACHE_E_NOCACHE_UPDATED;
-    return hr;
+    return S_OK;
+//    HRESULT hr = CACHE_E_NOCACHE_UPDATED;
+//    return hr;
 }
 
 STDMETHODIMP EmbedDocument_Impl::IsUpToDate()

File embedserv/source/inprocserv/advisesink.cxx

 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( LPFORMATETC pFetc, LPSTGMEDIUM pMedium )
 {
     if ( m_pListener )
+    {
+        WRITEDEBUGINFO( "OleWrapperAdviseSink::OnDataChange():" );
         m_pListener->OnDataChange( pFetc, pMedium );
+    }
 }
 
 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex )
 {
     if ( m_pListener )
+    {
+        WRITEDEBUGINFO( "OleWrapperAdviseSink::OnViewChange():" );
         m_pListener->OnViewChange( dwAspect, lindex );
+    }
 }
 
 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( LPMONIKER pMoniker )
 {
     if ( m_pListener )
+    {
+        WRITEDEBUGINFO( "OleWrapperAdviseSink::OnRename():" );
         m_pListener->OnRename( pMoniker );
+    }
 }
 
 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
 {
     if ( m_pListener )
+    {
+        WRITEDEBUGINFO( "OleWrapperAdviseSink::OnSave():" );
         m_pListener->OnSave();
+    }
 }
 
 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
 {
     if ( m_pListener )
+    {
+        WRITEDEBUGINFO( "OleWrapperAdviseSink::OnClose():" );
         m_pListener->OnClose();
+    }
 
     if ( m_bHandleClosed )
         m_bClosed = TRUE;

File embedserv/source/inprocserv/advisesink.hxx

     FORMATETC* GetFormatEtc() { return m_pFormatEtc; }
     DWORD GetAspect() { return m_nAspect; }
     ComSmart< IAdviseSink >& GetOrigAdvise() { return m_pListener; }
+    void DisconnectOrigAdvise() { m_pListener = NULL; }
     
     void SetClosed() { m_bClosed = TRUE; }
     void UnsetClosed() { m_bClosed = FALSE; }

File embedserv/source/inprocserv/dllentry.cxx

 
 
 namespace {
+    void FillCharFromInt( int nValue, char* pBuf, int nLen )
+    {
+        int nInd = 0;
+        while( nInd < nLen )
+        {
+            char nSign = ( nValue / ( 1 << ( ( nLen - nInd ) * 4 ) ) ) % 16;
+            if ( nSign >= 0 && nSign <= 9 )
+                pBuf[nInd] = nSign + '0';
+            else if ( nSign >= 10 && nSign <= 15 )
+                pBuf[nInd] = nSign - 10 + 'a';
+
+            nInd++;
+        }
+    }
+
     int GetStringFromClassID( const GUID& guid, char* pBuf, int nLen )
     {
-        if ( nLen < 27 )
+        // is not allowed to insert 
+        if ( nLen < 38 )
             return 0;
+        
+        pBuf[0] = '{';
+        FillCharFromInt( guid.Data1, &pBuf[1], 8 );
+        pBuf[9] = '-';
+        FillCharFromInt( guid.Data2, &pBuf[10], 4 );
+        pBuf[14] = '-';
+        FillCharFromInt( guid.Data3, &pBuf[15], 4 );
+        pBuf[19] = '-';
 
-        int nResult = sprintf( pBuf,
-                          "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
-                          guid.Data1,
-                          guid.Data2,
-                          guid.Data3,
-                          guid.Data4[0],
-                          guid.Data4[1],
-                          guid.Data4[2],
-                          guid.Data4[3],
-                          guid.Data4[4],
-                          guid.Data4[5],
-                          guid.Data4[6],
-                          guid.Data4[7] );
+        int nInd = 0;
+        for ( nInd = 0; nInd < 2 ; nInd++ )
+            FillCharFromInt( guid.Data4[nInd], &pBuf[20 + 2*nInd], 2 );
+        pBuf[24] = '-';
+        for ( nInd = 2; nInd < 8 ; nInd++ )
+            FillCharFromInt( guid.Data4[nInd], &pBuf[20 + 1 + 2*nInd], 2 );
+        pBuf[37] = '}';
 
-        if ( nResult && nResult < nLen )
-	        return ++nResult;
-
-        return 0;
+        return 38;
 	}
 
     HRESULT WriteLibraryToRegistry( char* pLibrary, DWORD nLen )
         if ( pLibrary && nLen )
         {
             HKEY hKey = NULL;
-            char* pPrefix = "Software\\Classes\\CLSID\\";
-            char* pPostfix = "\\InprocHandler32";
 
             hRes = S_OK;
             for ( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
             {
-                char pSubKey[513];
-                char pCLSID[64];
-                int nGuidLen = GetStringFromClassID( *guidList[nInd], pCLSID, 64 );
+                char* pSubKey = "Software\\Classes\\CLSID\\.....................................\\InprocHandler32";
+
+                int nGuidLen = GetStringFromClassID( *guidList[nInd], &pSubKey[23], 38 );
 
                 BOOL bLocalSuccess = FALSE;
-                if ( nGuidLen && nGuidLen < 64 )
+                if ( nGuidLen && nGuidLen == 38 )
                 {
-                    pCLSID[nGuidLen] = 0;
-                    sprintf( pSubKey, "%s%s%s", pPrefix, pCLSID, pPostfix );
                     if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, pSubKey, &hKey ) )
                     {
                         if ( ERROR_SUCCESS == RegSetValueEx( hKey, "", 0, REG_SZ, (const BYTE*)pLibrary, nLen ) )

File embedserv/source/inprocserv/inprocembobj.cxx

  *
  ************************************************************************/
 
-#include <stdio.h>
-
 #include <embservconst.h>
 #include "inprocembobj.h"
 
-// #define OWNDEBUG
-
-#ifdef OWNDEBUG
-#define WRITEDEBUGINFO( x ) WriteDebugInfo( x )
-#else
-#define WRITEDEBUGINFO( x )
-#endif
-
 namespace inprocserv
 {
 
+#ifdef OWNDEBUG
 //-------------------------------------------------------------------------------
-#ifdef OWNDEBUG
-void WriteDebugInfo( char* pString )
+void WriteDebugInfo( DWORD pThis, char* pString, DWORD nToWrite )
 {
-    FILE* pFile = fopen( "c:\\inproc.log", "aw" );
-    if ( pFile )
+    if ( nToWrite )
     {
-        fprintf( pFile, pString );
-        fclose( pFile );
+        char pNumber[12];
+        pNumber[0] = '0';
+        pNumber[1] = 'x';
+        for ( int nInd = 0; nInd < 8; nInd++ )
+            pNumber[nInd+2] = (char)( ( pThis / ( 1 << ( 7 - nInd ) ) ) % 16 ) + 48;  
+        pNumber[10] = ' ';
+        pNumber[11] = 0;
+
+        HANDLE pFile = CreateFileA( "h:\\inproc.log", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL );
+        if ( pFile )
+        {
+            DWORD dwWritten = 0;
+            SetFilePointer( pFile, 0, 0, FILE_END );
+            WriteFile( pFile, pNumber, 11, &dwWritten, NULL );
+            WriteFile( pFile, pString, nToWrite - 1, &dwWritten, NULL );
+            CloseHandle( pFile );
+        }
     }
 }
 #endif
 
 //-------------------------------------------------------------------------------
+BOOL StringsEqual( LPCOLESTR pszNameFromOutside, wchar_t* pOwnName )
+{
+    BOOL bResult = TRUE;
+
+    if ( pszNameFromOutside && pOwnName )
+    {
+        for ( int nInd = 0; pszNameFromOutside[nInd] != 0 || pOwnName[nInd] != 0; nInd++ )
+        {
+            if ( pszNameFromOutside[nInd] != pOwnName[nInd] )
+            {
+                bResult = FALSE;
+                break;
+            }
+        }
+    }
+    else if ( pszNameFromOutside || pOwnName )
+        bResult = FALSE;
+
+    return bResult;
+}
+
+//-------------------------------------------------------------------------------
 HRESULT InprocEmbedDocument_Impl::Init()
 {
 	return S_OK;
 }
 
 //-------------------------------------------------------------------------------
-void InprocEmbedDocument_Impl::SetFileName( LPCOLESTR pszFileName )
+void InprocEmbedDocument_Impl::SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName )
 {
+    if ( !pszNameFromOutside )
+        return;
+
     // copy the string
-    size_t nLen = wcslen( pszFileName );
-    if ( m_pFileName )
+    size_t nLen = 0;
+    while( pszNameFromOutside[nLen] != 0 )
+        nLen++;
+
+    if ( pOwnName )
     {
-        delete[] m_pFileName;
-        m_pFileName = NULL;
+        delete[] pOwnName;
+        pOwnName = NULL;
     }
-    m_pFileName = new wchar_t[nLen+1];
-    wcsncpy( m_pFileName, pszFileName, nLen );
-    m_pFileName[nLen] = 0;
+
+    pOwnName = new wchar_t[nLen+1];
+    for ( size_t nInd = 0; nInd < nLen; nInd++ )
+        pOwnName[nInd] = pszNameFromOutside[nInd];
+    pOwnName[nLen] = 0;
 }
 
 //-------------------------------------------------------------------------------
 BOOL InprocEmbedDocument_Impl::CheckDefHandler()
 {
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
     // set the own listener
     if ( m_pOleAdvises[0] == NULL )
     {
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         m_pOleAdvises[0] = new OleWrapperAdviseSink();
     }
     else
     {
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         if ( m_pOleAdvises[0]->IsClosed() )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             if ( m_pDefHandler )
             {
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                 // deregister all the listeners
 
                 ComSmart< IOleObject > pOleObject;
                 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
                 if ( SUCCEEDED( hr ) && pOleObject )
                 {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                         if ( m_pOleAdvises[nInd] )
                         {
                             pOleObject->Unadvise( nID );
                             m_pOleAdvises[nInd]->SetRegID( 0 );
                         }
+
+                    pOleObject->SetClientSite( NULL );
                 }
 
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                 ComSmart< IDataObject > pIDataObject;
                 hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
                 if ( SUCCEEDED( hr ) && pIDataObject )
                 {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                         if ( m_pDataAdvises[nInd] )
                         {
                         }
                 }
 
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                 ComSmart< IViewObject > pIViewObject;
                 hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
                 if ( SUCCEEDED( hr ) && pIViewObject )
                 {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                     if ( m_pViewAdvise )
                         pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), NULL );
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
+                }
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
+
+                ComSmart< IPersistStorage > pPersist;
+                hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
+                if ( SUCCEEDED( hr ) && pPersist )
+                {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
+                    // disconnect the old wrapper from the storage
+                    pPersist->HandsOffStorage();
                 }
 
                 m_pDefHandler = NULL;
             }
 
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             m_pOleAdvises[0]->UnsetClosed();
         }
     }
     if ( m_nCallsOnStack )
         return FALSE;
 
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
     if ( !m_pDefHandler )
     {
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         // create a new default inprocess handler
         HRESULT hr = OleCreateDefaultHandler( m_guid, NULL, IID_IUnknown, (void**)&m_pDefHandler );
         if ( SUCCEEDED( hr ) )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
 //            // reinit the handler
 //            ComSmart< IRunnableObject > pIRunObj;
 //            hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
                 {
                     if ( m_nInitMode == INIT_FROM_STORAGE )
                     {
+                        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                         ComSmart< IPersistStorage > pPersist;
                         hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
 
                     }
                     else if ( m_nInitMode == LOAD_FROM_STORAGE )
                     {
+                        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                         ComSmart< IPersistStorage > pPersist;
                         hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
 
                     }
                     else if ( m_nInitMode == LOAD_FROM_FILE )
                     {
+                        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                         ComSmart< IPersistFile > pPersistFile;
                         hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersistFile );
 
                         if ( SUCCEEDED( hr ) && pPersistFile && m_pFileName )
                             hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode );
                     }
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                 }
             }
         }
 
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         if ( !SUCCEEDED( hr ) || !m_pDefHandler )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             m_pDefHandler = NULL;
             return FALSE;
         }
         hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
         if ( SUCCEEDED( hr ) && pOleObject )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             if ( m_pClientSite )
                 pOleObject->SetClientSite( m_pClientSite );
-
+            
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                 if ( m_pOleAdvises[nInd] )
                 {
                 }
         }
 
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         ComSmart< IDataObject > pIDataObject;
         hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
         if ( SUCCEEDED( hr ) && pIDataObject )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                 if ( m_pDataAdvises[nInd] )
                 {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                     DWORD nRegID = 0;
                     if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd], &nRegID ) ) && nRegID > 0 )
                         m_pDataAdvises[nInd]->SetRegID( nRegID );
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
                 }
         }
 
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         ComSmart< IViewObject > pIViewObject;
         hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
         if ( SUCCEEDED( hr ) && pIViewObject )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
             if ( m_pViewAdvise )
                 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise );
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
         }
     }
 
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
+
     return TRUE;
 }
 
 {
     m_pDefHandler = (IUnknown*)NULL;
 
+    // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
     {
         if ( m_pOleAdvises[nInd] )
         {
-            ComSmart< OleWrapperAdviseSink > pAdvice = m_pOleAdvises[nInd];
+            ComSmart< OleWrapperAdviseSink > pAdvise = m_pOleAdvises[nInd];
             m_pOleAdvises[nInd] = NULL;
         }
 
         if ( m_pDataAdvises[nInd] )
         {
-            ComSmart< OleWrapperAdviseSink > pAdvice = m_pDataAdvises[nInd];
+            ComSmart< OleWrapperAdviseSink > pAdvise = m_pDataAdvises[nInd];
             m_pDataAdvises[nInd] = NULL;
         }
     }
 
+    m_pViewAdvise = NULL;
+
     m_nInitMode = NOINIT;
     m_pStorage = NULL;
+
+    if ( m_pOleContainer )
+    {
+        m_pOleContainer->LockContainer( FALSE );
+        m_pOleContainer = NULL;
+    }
+
     m_pClientSite = NULL;
 
     m_nFileOpenMode = 0;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::IsDirty()
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()1\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()1" );
     if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
         return S_FALSE;
 
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()2\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()2" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistStorage > pPersist;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitNew( IStorage *pStg )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitNew( IStorage *pStg )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistStorage > pPersist;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
     if ( CheckDefHandler() )
     {
+        WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
         ComSmart< IPersistStorage > pPersist;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
         
         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
         if ( SUCCEEDED( hr ) && pPersist )
         {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
             hr = pPersist->Load( pStg );
             if ( SUCCEEDED( hr ) )
             {
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
                 m_nInitMode = LOAD_FROM_STORAGE;
                 m_pStorage = pStg;
 
                 m_nFileOpenMode = 0;
                 if ( m_pFileName )
                 {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
                     delete[] m_pFileName;
                     m_pFileName = NULL;
                 }
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )1\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
     if ( fSameAsLoad && ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) )
         return S_OK;
 
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )2\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistStorage > pPersist;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )1\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
     if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
     {
         if ( pStgNew )
         return S_OK;
     }
 
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )2\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistStorage > pPersist;
             hr = pPersist->SaveCompleted( pStgNew );
             if ( SUCCEEDED( hr ) )
             {
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
                 m_nInitMode = LOAD_FROM_STORAGE;
                 if ( pStgNew )
+                {
+                    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
                     m_pStorage = pStgNew;
+                }
 
                 m_nFileOpenMode = 0;
                 if ( m_pFileName )
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage()
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistStorage > pPersist;
         
         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
         if ( SUCCEEDED( hr ) && pPersist )
-            return pPersist->HandsOffStorage();
+        {
+            hr = pPersist->HandsOffStorage();
+            if ( SUCCEEDED( hr ) )
+            {
+                m_pStorage = NULL;
+                WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
+            }
+
+            return hr;
+        }
     }
 
     return E_FAIL;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )" );
     if ( CheckDefHandler() && pszFileName )
     {
         ComSmart< IPersistFile > pPersist;
 
                 m_nFileOpenMode = dwMode;
                 // copy the string
-                SetFileName( pszFileName );
+                SetName( pszFileName, m_pFileName );
             }
 
             return hr;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistFile > pPersist;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistFile > pPersist;
 
                 m_nFileOpenMode = STGM_READWRITE; // was just written
                 // copy the string
-                SetFileName( pszFileName );
+                SetName( pszFileName, m_pFileName );
             }
         }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IPersistFile > pPersist;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )" );
+    if ( pSite == m_pClientSite )
+        return S_OK;
+
+    if ( !pSite )
+    {
+        m_pClientSite = NULL;
+        if ( m_pOleContainer )
+        {
+            m_pOleContainer->LockContainer( FALSE );
+            m_pOleContainer = NULL;
+        }
+    }
+
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
         {
             HRESULT hr = pOleObject->SetClientSite( pSite );
             if ( SUCCEEDED( hr ) )
+            {
                 m_pClientSite = pSite;
 
+                if ( m_pOleContainer )
+                {
+                    m_pOleContainer->LockContainer( FALSE );
+                    m_pOleContainer = NULL;
+                }
+                
+                m_pClientSite->GetContainer( &m_pOleContainer );
+                if ( m_pOleContainer )
+                    m_pOleContainer->LockContainer( TRUE );
+            }
+
             return hr;
         }
     }
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
+
+    HRESULT hr = S_OK;
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
         
         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
         if ( SUCCEEDED( hr ) && pOleObject )
-            return pOleObject->SetHostNames( szContainerApp, szContainerObj );
+        {
+            WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
+            hr = pOleObject->SetHostNames( szContainerApp, szContainerObj );
+        }
     }
 
-    return E_FAIL;
+    return hr;
 }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )\n" );
-    if ( CheckDefHandler() )
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )" );
+    if ( m_pDefHandler && CheckDefHandler() )
     {
+        // no need to close if there is no default handler.
         ComSmart< IOleObject > pOleObject;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
         
 		{
             hr = pOleObject->Close( dwSaveOption );
 			hr = CoDisconnectObject( (IUnknown*)(IPersistStorage*)this, 0 );
-
-            // if the object is closed from outside that means that it should go to uninitialized state
-            Clean();
-
-			return S_OK;
 		}
     }
 
-    return E_FAIL;
+    // if the object is closed from outside that means that it should go to uninitialized state
+    Clean();
+
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 	HWND hWin,
 	LPCRECT pRect )
 {
-    WRITEDEBUGINFO( "DoVerb\n" );
+    WRITEDEBUGINFO( "DoVerb" );
     if ( CheckDefHandler() )
     {
+        WRITEDEBUGINFO( "DoVerb" MY_STRING_LINE "n" );
         ComSmart< IOleObject > pOleObject;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
         
+        WRITEDEBUGINFO( "DoVerb" );
         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
+        WRITEDEBUGINFO( "DoVerb" );
         if ( SUCCEEDED( hr ) && pOleObject )
-            return pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
+        {
+            WRITEDEBUGINFO( "DoVerb" );
+            hr = pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
+            if ( SUCCEEDED( hr ) )
+            {
+                WRITEDEBUGINFO( "DoVerb" );
+            }
+
+            return hr;
+        }
+
+        WRITEDEBUGINFO( "DoVerb" );
     }
 
     return E_FAIL;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Update()
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()\n" );
-    if ( CheckDefHandler() )
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()" );
+
+    if ( m_pDefHandler && CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
             return pOleObject->Update();
     }
 
-    return E_FAIL;
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )\n" );
-    if ( CheckDefHandler() )
-    {
-        ComSmart< IOleObject > pOleObject;
-        HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
-        
-        ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
-        if ( SUCCEEDED( hr ) && pOleObject )
-            return pOleObject->GetUserClassID( pClsid );
-    }
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )" );
+    if ( pClsid )
+        *pClsid = m_guid;
 
-    return E_FAIL;
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )" );
+	
+    if ( !pdwConnection )
+        return E_FAIL;
+
+	// CheckDefHandler will set the listener, avoid reusing of old listener
+    if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
+    {
+        m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
+        m_pOleAdvises[*pdwConnection] = NULL;
+    }
+
     if ( pAdvSink && CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
         }
     }
 
-    return E_FAIL;
+    // return success always for now
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
             if ( SUCCEEDED( hr ) && pOleObject )
             {
                 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
-                return pOleObject->Unadvise( nID );
+                pOleObject->Unadvise( nID );
             }
         }
 
+        m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
         m_pOleAdvises[dwConnection] = NULL;
+
+        return S_OK;
     }
 
     return E_FAIL;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleObject > pOleObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )\n" );
-    if ( pAdvSink && CheckDefHandler() )
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )" );
+
+    if ( !pdwConnection )
+        return E_FAIL;
+
+	// avoid reusing of the old listener
+	if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
+    {
+        m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
+        m_pDataAdvises[*pdwConnection] = NULL;
+    }
+
+	if ( pAdvSink && CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
         }
     }
 
-    return E_FAIL;
+    // return success always for now
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )" );
     if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
     {
         if ( CheckDefHandler() )
             if ( SUCCEEDED( hr ) && pIDataObject )
             {
                 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
-                return pIDataObject->DUnadvise( nID );
+                pIDataObject->DUnadvise( nID );
             }
         }
 
+        m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
         m_pDataAdvises[dwConnection] = NULL;
+
+        return S_OK;
     }
 
     return E_FAIL;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDataObject > pIDataObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IRunnableObject > pIRunObj;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IRunnableObject > pIRunObj;
 //-------------------------------------------------------------------------------
 BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning()
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()" );
    if ( CheckDefHandler() )
     {
         ComSmart< IRunnableObject > pIRunObj;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )" );
    if ( CheckDefHandler() )
     {
         ComSmart< IRunnableObject > pIRunObj;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)" );
    if ( CheckDefHandler() )
     {
         ComSmart< IRunnableObject > pIRunObj;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IViewObject > pIViewObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IViewObject > pIViewObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IViewObject > pIViewObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IViewObject > pIViewObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )\n" );
-    if ( CheckDefHandler() )
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )" );
+
+	// CheckDefHandler will set the listener, avoid reusing of old listener
+    if ( m_pViewAdvise )
+    {
+        m_pViewAdvise->DisconnectOrigAdvise();
+	    m_pViewAdvise = NULL;
+    }
+
+    if ( pAdvSink && CheckDefHandler() )
     {
         ComSmart< IViewObject > pIViewObject;
         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
         }
     }
 
-    return E_FAIL;
+    return S_OK;
 }
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IViewObject2 > pIViewObject2;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleWindow > pIOleWindow;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleWindow > pIOleWindow;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate( void )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate( void )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo( void )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDispatch > pIDispatch;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDispatch > pIDispatch;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDispatch > pIDispatch;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )" );
     if ( CheckDefHandler() )
     {
         ComSmart< IDispatch > pIDispatch;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache > pIOleCache;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache > pIOleCache;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache > pIOleCache;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache > pIOleCache;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache > pIOleCache;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache2 > pIOleCache2;
 //-------------------------------------------------------------------------------
 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
 {
-    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )\n" );
+    WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )" );
     if ( m_rOwnDocument.CheckDefHandler() )
     {
         ComSmart< IOleCache2 > pIOleCache2;

File embedserv/source/inprocserv/inprocembobj.h

     ComSmart< IStorage > m_pStorage;
 
     ComSmart< IOleClientSite > m_pClientSite;
+    ComSmart< IOleContainer >  m_pOleContainer;
 
     ULONG m_nCallsOnStack;
 
     {}
 
     HRESULT Init();
-    void SetFileName( LPCOLESTR pszFileName );
+    void SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName );
 
     BOOL CheckDefHandler();
     ComSmart< IUnknown >& GetDefHandler() { return m_pDefHandler; }

File embedserv/source/inprocserv/makefile.mk

 
 LIBTARGET=NO
 USE_DEFFILE=YES
+LIBCMT=libcmt.lib
+UWINAPILIB=
 
 # --- Files -------------------------------------
 

File embedserv/source/inprocserv/smartpointer.hxx

 #ifndef _INPROCSERV_SMARTPOINTER_HXX_
 #define _INPROCSERV_SMARTPOINTER_HXX_
 
+// #define OWNDEBUG
+
+#ifdef OWNDEBUG
+#define WRITEDEBUGINFOINTERN( x ) WriteDebugInfo( (DWORD)this, x, sizeof( x ) )
+#define WRITEDEBUGINFO( x ) WRITEDEBUGINFOINTERN( x ":" MY_STRING_LINE "\n" )
+#define TO_STRING( x ) #x
+#define MACRO_VALUE_TO_STRING( x ) TO_STRING( x )
+#define MY_STRING_LINE MACRO_VALUE_TO_STRING( __LINE__ )
+#else
+#define WRITEDEBUGINFO( x ) void()
+#define MY_STRING_LINE
+#endif
+
+
 namespace inprocserv{
 
+void WriteDebugInfo( DWORD pThis, char* pString, DWORD nToWrite );
+
 template< class T > class ComSmart
 {
     T* m_pInterface;

File sw/source/filter/ww8/wrtww8.cxx

         }
     }
 
-    SwTwips nSz = nTblOffset;
+    SwTwips nSz = 0;
     sal_uInt32 n = 0;
     InsUInt16(nTblOffset); 
     
         SwTwips nCalc = nSz;
         if (bRelBoxSize)
             nCalc = (nCalc * nPageSize) / nTblSz;
+            
+        nCalc += nTblOffset;
         
         InsUInt16(static_cast<USHORT>(nCalc));        
     }