if( isOpened ){
file.Close();
}
if( pBuffer != NULL ){
delete pBuffer;
pBuffer = NULL;
}
return m_ReadedSize;
}
HRESULT PerformDirectory( const char *path, IStorage *storage ){
HRESULT hr = 0L;
long hFile = 0;
USES_CONVERSION;
_finddata_t fileinfo;
int ch = _chdir( path );
if (( hFile = _findfirst( "*.*", &fileinfo ) ) != -1 ){
do{
if (!(fileinfo.attrib & _A_SUBDIR))
{
char filename[_MAX_PATH];
strcpy( filename, path );
strcat( filename, fileinfo.name );
CComPtr<IStream> fileStream;
hr = storage->CreateStream( T2W( fileinfo.name ), STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, NULL, &fileStream );
ASSERT( SUCCEEDED( hr ) );
PerformFileStream( filename, fileStream );
}
else{
if ( strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0 )
{
char subdir[ _MAX_PATH ];
strcpy( subdir,path );
strcat( subdir,fileinfo.name);
strcat(subdir,"\\");
CComPtr<IStorage> sub;
hr = storage->CreateStorage( T2W( fileinfo.name ),
STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0,
&sub);
ASSERT( SUCCEEDED( hr ) );
hr = PerformDirectory( subdir, sub );
ASSERT( SUCCEEDED( hr ) );
}
}
}while (_findnext(hFile,&fileinfo) == 0);
_findclose(hFile);
}
return hr;
}
HRESULT CreateDirectoryStorage( const char *path, IStorage **stg )
{
HRESULT hr = 0L;
hr = StgCreateStorageEx( NULL,
STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
STGFMT_STORAGE,
// STGFMT_STORAGE => Structured Storage property sets
// STGFMT_FILE => NTFS property sets
0, NULL, NULL,
IID_IStorage,
reinterpret_cast<void**>(stg) );
if( FAILED(hr) ) throw L"Failed StgCreateStorageEx";
hr = PerformDirectory( path, (*stg) );
return hr;
}
这样我们就可以将这个创建好的IStorage对象写入到CD或DVD中了。
hr = jdm->AddData( storage, FALSE );
if( SUCCEEDED( hr ) ){
hr = dm->RecordDisc( FALSE, TRUE );
}
这里由于在调用了RecordDisc后方写入到CD,同时,这里将可能产生许多问题,如CD不能被刻录等问题都需要在这里进行处理。
VS.NET 2003/2005都提供了如何使用Imapi进行CD刻录的帮助,详细内容请参考相关的MSDN。