2012-08-07 35 views
0

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

一件整合涉及一个Shell Preview提供程序,代码非常直接,但是,我坚持实现某些东西的最佳方式。

外壳是给我,通过我的预览处理程序,IStream对象,我需要转换/使其适应一个std :: ifstream的对象,主要目的是让的std ::函数getline可以得到进一步呼吁下调用堆栈。

我想知道是否有一个“标准”的做法适应或我需要角色我的袖子和代码?

TIA。

回答

0

与此周围Faffed了一会儿:

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