StgopenstorageEx

hr1 = ::StgOpenStorageEx(s.AllocSysString() ,

STGM_READ | STGM_SHARE_EXCLUSIVE ,

STGFMT_STORAGE,

0,0,0,

IID_IPropertySetStorage ,

(void**) &pPropSetStg);

it gives result correct as S_OK

but again i am trying to open that storage it gives share violation as useal

but i want to open that storage again in read only mode ..

can anyone help me how to write following code (Eg .correction in flags etc so that i will get S_OK)

hr1 = ::StgOpenStorageEx(s.AllocSysString() ,

STGM_READ | STGM_SHARE_EXCLUSIVE |STGM_TRANSACTED ,

STGFMT_STORAGE,

0,0,0,

IID_IPropertySetStorage ,

(void**) &pPropSetStg);



Answer this question

StgopenstorageEx

  • Sai A

    Thanks Viorel ,its working perfectly .also

    STGM_READ |STGM_TRANSACTED its working perfectly .


  • Tom bernard

    c:\downloads smells like a folder, not a file name.


  • LukeyPoo

    Thanks, I'll try it out.
  • Binu Jeesman

    No i am not closing before opening it.

    i want to know that is it possible to reopen (even in read only mode) or not

    -Rupesh


  • Vayse_Dev

    Perhaps you're misinterpreting the meaning of STGFMT_STORAGE vs STGFMT_FILE They control the structure of the storage, compound file vs single file. The path argument to StgOpenStorageEx() must be point to a file, not a folder. If c:\downloads is actually a file and not a folder I'm on the wrong track.


  • logtorahul

    Well, if I wanted to open a file I would have tried using STGFMT_FILE or the OpenStorage function. According to the following a folder is Storage and file is Stream.

    "IStorage

    The IStorage interface supports the creation and management of structured storage objects. Structured storage allows hierarchical storage of information within a single file, and is often referred to as "a file system within a file". Elements of a structured storage object are storages and streams. Storages are analogous to directories, and streams are analogous to files. Within a structured storage there will be a primary storage object that may contain substorages, possibly nested, and streams. Storages provide the structure of the object, and streams contain the data, which is manipulated through the IStream interface." from: http://msdn2.microsoft.com/en-us/library/aa380015.aspx

    What I want to do is add the folder contents, including subfolders and all files, to the Image for burning. Please correct me if I am trying to use the wrong function or parameters. Thanks.


  • Gavin Rouse

    Here's a code sample that might be useful...


  • rKarthik

    Ok, I have tried the sample, I get it to compile and so on, but I have a problem still. Heres some of my code again. This would be before calling the sample code function. It is without a loop because I am trying to figure out where the problem is. The StgCreateStorageEx returns that it was successful. But when it gets to the pStg->CreateStorage it has some kind of error, no returned HRESULT, and tries to debug it.

    SetCurrentDirectory("C:");

    IStorage* pStg;

    hr=StgCreateStorageEx(L"Downloads",

    STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED,

    STGFMT_STORAGE,

    0,0,0,

    IID_IStorage,

    (void**)pStg);

    std::cout << " Creating Storage Root : " << gethresult(hr);

    SetCurrentDirectory("C:\\Downloads");

    IStream *pStream;

    hr=pStg->CreateStream(L"TestBurn.zip",

    STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,

    0, 0,

    &pStream);

    std::cout << " Add File : " << gethresult(hr);


  • Alessandro Camargo

    I'm trying to view that code but I cant get to it, I get "The connection was reset" . Could you send me that code to my mail (josip.cagalj@kron.hr)
    THX
    P.S.
    I'm writing an application who can among other stuff record data. I don't have any troubles recording files, but with folders (and subfolders) I am. First I use:
    StgCreateDocfile( NULL, STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, &pStorage)

    then for root folder:
    pStorage->CreateStorage(A2W(dir_name.operator LPCTSTR()),
    STGM_CREATE |STGM_READWRITE |STGM_SHARE_EXCLUSIVE |
    STGM_DIRECT |STGFMT_STORAGE, 0, 0, &pDirStorage)

    and for files within I create streams:
    pDirStorage->CreateStream(A2W(F_name.operator LPCTSTR()),
    STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
    0, 0, &pDirFileStream)

    than I read into from files:
    pDirFileStream->Write(pBuffer,nSize,NULL)
    pDirFileStream->Commit(STGC_OVERWRITE)
    hr= pDirFileStream->Release()

    for all files in folder!
    If root folder contains sub folders I call my function which is recursive!
    I get error on my pIJolietDiscMaster->AddData(pStorage) saying "Insufficient permissions to create stream" !
    Am I doing something wrong with last code (stream write,commit,release)
    Should I use 'StgCreateStorageEx' instead of 'StgCreateDocfile'
    If it's in some interest I could post my code.
    Thanks for participating in forum and helping us resolving problems.
    As I mentioned earlier I can review linked post so if someone could post it it wold help me



  • wei917

    File sharing is handle based, not application or user based. You've locked yourself out with STGM_SHARE_EXCLUSIVE.


  • insaneolly

    I'm going to start this thread up again.

    I am trying to use StgOpenStorageEx with an IJolietDiscMaster's AddData function.

    For the AddData function you need an IStorage object. So I create the IStorage object and then try to set it up with the StgOpenStorageEx function. Then I get an error and when checking the HRESULT with the FormatMessage function, it gives me "Access Denied.". The folder does exist, obviously not with 2 \ but when removing it, it wont work and I have tried. Yes I'm new to all these string types. Can someone please help me out. Heres my StgOpenStorageEx code:

    const WCHAR* path=L"C:\\downloads";

    IStorage *pStg;

    hr = StgOpenStorageEx(path,

    STGM_READ | STGM_TRANSACTED,

    STGFMT_STORAGE,

    NULL, NULL, NULL,

    IID_IStorage,

    (void**)(&pStg) );


  • pkv

    I think instead of STGM_READ | STGM_SHARE_EXCLUSIVE modes you should try STGM_READ | STGM_SHARE_DENY_WRITE in both cases.

    I hope it helps.


  • fatquack

    No, your correct, I only realized that now. Anyway then, can you maybe tell me how I can add a normal NTFS folder and all its contents to the IJolietDiscMaster for burning
  • tizza2k

    Did you close the storage object before you tried to open it again


  • StgopenstorageEx