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.

push 22
  • 1,172
  • 3
  • 15
  • 34

1 Answers1

0

Faffed around with this for a while:

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());

But didn't like having to read it all into memory, for it to be processed again.

So I implemented my preview handler using IInitializeWithFile instead.

push 22
  • 1,172
  • 3
  • 15
  • 34