Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//#include <stdafx.h>
#include <stdio.h>
#include<conio.h>

#include <windows.h>
#include<shobjidl.h>
#include <ole2.h>
#include<objidl.h>
#define BUFFERSIZE 1024

EXTERN_C void wmain()
{
HRESULT hr ;
IStorage *pStg;
IStorage* pStg1;
IStorage *pStg2;
WCHAR *pwszError = L"";

IStream *pSt=NULL;



hr = StgOpenStorageEx( L"E:\\Root.stg",
STGM_READ|STGM_SHARE_DENY_WRITE,
STGFMT_DOCFILE,
0, NULL, 0,
IID_IPropertySetStorage,
reinterpret_cast<void**>(&pStg) );
if(hr==S_OK)
printf("Storage opened");

hr=pStg->OpenStream(L"Rodies.mp3",NULL,STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,0,(void**)&pStg);
if(hr==S_OK)
printf("Stream opened");
else
printf("Not Opened");

_getch();


}
Posted
Updated 21-Mar-11 8:11am
v4
Comments
Vinayak Pingale 21-Mar-11 2:51am    
the following error is shown:

Error 1 error C2664: 'IStorage::OpenStream' : cannot convert parameter 5 from 'void **' to 'IStream **' c:\users\sumit\documents\visual studio 2008\projects\recovery module\recovery module\recovery.cpp 32
Sergey Alexandrovich Kryukov 21-Mar-11 3:17am    
Well, comment this line 32 in your code; why making people guess?!
--SA
[no name] 21-Mar-11 3:36am    
This line reinterpret_cast<void**>(&pStg)?
Try (void**)&pStg

* Dont forget that the REFIID corresponds to the interface you want:
IID_IPropertySetStorage wants IPropertySetStorage*
IID_IStorage wants IStorage*
* Dont forget to release interfaces after usage.
* Dont forget use interfaces only valid if the return value (HRESULT) == S_OK.
This looks better:
IStorage*    pStorage;
IStream*    pStream;
HRESULT      hr;

hr = StgOpenStorageEx
      (
        L"E:\\Root.stg",
        STGM_READ|STGM_SHARE_DENY_WRITE,
        STGFMT_DOCFILE,
        0, NULL, 0,
        IID_IStorage,
        (void**)&pStorage
      );

if(S_OK==hr)
{
  printf("Storage opened");

  if(S_OK==pStorage->OpenStream(L"Rodies.mp3",NULL,STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,0,(void**)&pStream))
  {
    printf("Stream opened");
    pStream->Release();
  }
  else
  {
    printf("Not Opened");
  }
  pStorage->Release();
}

_getch();

Good luck.
 
Share this answer
 
its becuase IStorage is not a valid object. can you show us the initialization OpenStream
 
Share this answer
 
Comments
Vinayak Pingale 21-Mar-11 14:15pm    
First i have opened already existing storage (.stg) using that storage pointer i have tried to open stream present in the storage.

but i am getting access violation error " 0xC0000005: Access violation writing location 0x00001012."
is it due to the modes that i am using while opening the stream

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900