• http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx


    http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx

    ————————————————————————————————————————————————————————

    This is one of the interesting cases I had lately. My customer was using DSOFramer sample to host Office Documents, but whenever he tried to open and save Word 2007 documents in this manner, guess what !! the file seems to be deleted !

    As I am basically a VB guy I did not want to bother myself with VC++ code of DSOFramer, because I've had easier ways to troubleshoot. The first thing I tried was Process Monitor from sysinternals. I could see that we are moving the file to a temp directory and then while saving it we are saving the changes in it. hmm..strange!

    Then I checked DSOFramer code and I realized that IPersist:Save() is returning S_OK, it doesn't look like there is some issue whatsoever. Then moved to Word 2007 code, to me it looks like a bug in the implementation of IPersist:Save().

    So ..to tackle this I had to modify the code of DSOFramer a bit, being more precise I modified the code of "CDsoDocObject::SaveStorageToFile" [this is in source file dsofdocobj.cpp]. Here is the modified code:

    if (SUCCEEDED(hr = m_pole->QueryInterface(IID_IPersistFile, (void**)&pipfile))) 
    { 
        //Get the current open file 
        LPWSTR pwszCurPath = new WCHAR(MAX_PATH+1);
        pipfile->GetCurFile(&pwszCurPath); 
        //Perform save. 
        hr = pipfile->Save(pwszFile, FALSE); 
        pipfile->Release(); 
        //Save results S_OK, but the document is saved to the original location (IPersistFile->GetCurFile) in Word 2007. 
        //We will just check if that's the case and move the file. 
        if (SUCCEEDED(hr) && !FFileExists(pwszFile)) 
        { 
            //We should come here only in case of Word 2007. 
            CopyFileW(pwszCurPath, pwszFile, TRUE); 
        } 
    } 

    Ok..bye for now.. will be  back in a day with some more, and yes I am starting to do technorati and del.icio.us tagging

     
     
     
     
     
    • I've tried this change in my version of the DSOFramer and I get a compile time error as there is no variable available called pwsxCurPath.

      I downloaded my source from the KB311765 link (same as the one you provide links to).

      Did you get your source from somewhere else?

      Asim Shah (asimshah@hotmail.com)

      Hey..i am sorry ..there was a typo in my code..i corrected it
       
    • Can someone please send to me the working dsoframer fixed to: jag_vb at. hotmail

      thnks

      Hello ..sir, nobody will send it to you. You 'll need to work on it! its a sample, provided as-is, and i am sorry there was a typo in my code, i corrected it
       
    • According to MSDN, IPersistFile::GetCurFile allocates the string buffer for you so I think there's a memory leak in your code.

      Here's what I believe to be correct (not yet tested though):

      //Get the current open file

      LPWSTR pwszCurPath = NULL;

      if (S_OK != pipfile->GetCurFile(&pwszCurPath))

      {

      pwszCurPath = NULL;

      }

      //Perform save.

      hr = pipfile->Save(pwszFile, FALSE);

      pipfile->Release();

      //Save results S_OK, but the document is saved to the original location (IPersistFile->GetCurFile) in Word 2007.

      //We will just check if that's the case and move the file.

      if (SUCCEEDED(hr) && !FFileExists(pwszFile) && pwszCurPath != NULL)

      {

      //We should come here only in case of Word 2007.

      CopyFileW(pwszCurPath, pwszFile, TRUE);

      }

      if (pwszCurPath != NULL)

      {

      CoTaskMemFree(pwszCurPath);

      pwszCurPath = NULL;

      }

  • 相关阅读:
    Nginx详解十四:Nginx场景实践篇之代理服务
    PyCharm设置字体风格
    PyCharm+SVN
    Nginx详解十三:Nginx场景实践篇之防盗链
    Nginx详解十二:Nginx场景实践篇之跨站访问相关
    Nginx详解十一:Nginx场景实践篇之Nginx缓存
    Nginx详解十:Nginx场景实践篇之Nginx静态资源场景配置
    Nginx详解九:Nginx基础篇之Nginx的访问控制
    浅谈控件(组件)制作方法一(附带一delphi导出数据到Excel的组件实例)(原创)
    切断数据感知控件,大大提升软件运行速度
  • 原文地址:https://www.cnblogs.com/cuizhf/p/3428928.html
Copyright © 2020-2023  润新知