【问题标题】:converting a windows shell IStream to std::ifstream/std::get_line将 Windows shell IStream 转换为 std::ifstream/std::get_line
【发布时间】:2012-08-07 12:45:58
【问题描述】:

我们编写了很多使用标准模板库的代码。我想将我们的一些应用程序集成到 windows shell 中,这应该为我们的用户提供更好的体验。

其中一个集成涉及一个 Shell Preview 提供程序,代码非常简单,但是,我被困在实现某些东西的最佳方式上。

shell 通过我的预览处理程序给了我一个 IStream 对象,我需要将它转换/调整为一个 std::ifstream 对象,主要是为了可以在调用堆栈中进一步调用 std::getline。

我想知道是否有一种“标准”的方式来进行改编,还是我需要发挥作用并编写代码?

TIA。

【问题讨论】:

    标签: ifstream windows-shell getline


    【解决方案1】:

    为此烦恼了一阵子:

    std::stringstream buff;
    BYTE ib[2048];
    ULONG totread=0, read=0, sbuff = 2048;
    HRESULT hr;
    do {
        hr = WinInputStream->Read(ib, sbuff, &read);
        buff.write(ib, read);
        totread+=read;
    } while((sbuff == read) && SUCCEEDED(hr));
    
    if(totread == 0) return false;
    ifstream i;
    TCHAR* ncbuff = const_cast<TCHAR*>(buff.str().c_str());
    i.rdbuf()->pubsetbuf(ncbuff, buff.str().length());
    

    但不喜欢将其全部读入内存,以便再次处理。

    所以我改用 IInitializeWithFile 实现了我的预览处理程序。

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      • 2018-09-26
      相关资源
      最近更新 更多