2012-08-07 68 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來實現預覽處理程序。