0

We have a lot of code written that makes use of the standard template library. I would like to integrate some of our apps into the windows shell, which should provide a better experience for our users.

One piece of integration involves a Shell Preview provider, the code is very straight forward, however, I’m stuck on the best way to implement something.

The shell is giving me, via my preview handler, an IStream object and I need to convert/adapt it to an std::ifstream object, primarily so that std::getline can get called further down the callstack.

I was wondering if there was a “standard” way of doing the adapting or do I need to role up my sleeves and code?

TIA.

4

1 回答 1

0

纠结了一阵子:

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 实现了我的预览处理程序。

于 2012-08-08T11:22:09.453 回答