BindToContext, hr = E_FAIL (the saga continues)
Hi All,
I'm attempting to generalize previous code. pFileMoniker->BindToStorage
fails with E_FAIL.
Here's what I know from MSDN:
* Files are abstracted through IStream
* Directories are persisted through IStorage
* IMoniker derives from IPersistStream
Any ideas? I've tried IID_IStream, IID_IPersistStream, and
IID_IPersistStreamInit (using T = IStream, IPersistStream, and
IPersistStreamInit respectively).
Jeff
/////////////////////////////////////////////////////
// Moniker Set Up
/////////////////////////////////////////////////////
CComPtr< IMoniker > pFileMoniker;
CComBSTR filename = OLESTR( "C:\\Test.html" );
hr = CreateFileMoniker( filename, &pFileMoniker );
if( FAILED( hr ) ) { throw (UINT)__LINE__ - 1; }
/////////////////////////////////////////////////////
// Binding Context
/////////////////////////////////////////////////////
CComPtr< IBindCtx > pBindContext;
hr = CreateBindCtx( 0 /*Reserved*/, &pBindContext );
if( FAILED( hr ) ) { throw (UINT)__LINE__ - 1; }
BIND_OPTS2 options;
ZeroMemory( &options, sizeof( &options ) );
options.cbStruct = sizeof( options );
options.grfMode = STGM_READ | STGM_SHARE_DENY_NONE | STGM_SIMPLE;
options.grfFlags = 0;
hr = pBindContext->SetBindOptions( &options );
if( FAILED( hr ) ) { throw (UINT)__LINE__ - 1; }
/////////////////////////////////////////////////////
// Moniker Binding
/////////////////////////////////////////////////////
CComPtr< IStream > pFileStream;
hr = pFileMoniker->BindToStorage( pBindContext, NULL, IID_IStream,
reinterpret_cast<PVOID*>( &pFileStream ) );
if( FAILED( hr ) ) { throw (UINT)__LINE__ - 1; }