alax_rosh
alax_rosh

Reputation: 23

Problems with extracting file summary information

I apologize for my English, it's not good, but I hope you will understand my question. I have problem with usage of WinAPI function StgOpenStorageEx. I need to get file's summary information. I found some solutions, but in all of them I need to use StgOpenStorageEx. Because it is not in standard modules, I declared it myself as exported from ole32.dll like this

function StgOpenStorageEx (
  const pwcsName : POleStr;  //Pointer to the path of the
                             //file containing storage object
  grfMode : LongInt;         //Specifies the access mode for the object
  stgfmt : DWORD;            //Specifies the storage file format
  grfAttrs : DWORD;          //Reserved; must be zero
  pStgOptions : Pointer;     //Address of STGOPTIONS pointer
  reserved2 : Pointer;       //Reserved; must be zero
  riid : PGUID;              //Specifies the GUID of the interface pointer 
  out stgOpen :              //Address of an interface pointer
  IStorage ) : HResult; stdcall; external 'ole32.dll';   

Next I need to use this function like this

    var
        res, open: hresult;
        stg: IStorage;
        PropSetStg: IPropertySetStorage;
        PropStg: IPropertyStorage;
        FileName: string;

    const
        IID_IPropertySetStorage : TGUID =     '{0000013A-0000-0000-C000-000000000046}';
        FmtID_SummaryInformation: TGUID =     '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';

    function StgOpenStorageEx (
     const pwcsName : POleStr;  //Pointer to the path of the
                                //file containing storage object
     grfMode : LongInt;         //Specifies the access mode for the object
     stgfmt : DWORD;            //Specifies the storage file format
     grfAttrs : DWORD;          //Reserved; must be zero
     pStgOptions : Pointer;     //Address of STGOPTIONS pointer
     reserved2 : Pointer;       //Reserved; must be zero
     riid : PGUID;              //Specifies the GUID of the interface pointer
     out stgOpen :              //Address of an interface pointer
     IStorage ) : HResult; stdcall; external 'ole32.dll';
     ...
     implementation
     ...
     FileName:=OpenDialog1.FileName;
     res:=StgOpenStorageEx(PWideChar(FileName),
        STGM_READ or STGM_SHARE_DENY_WRITE,
        STGFMT_FILE,
        0, nil,  nil, @IID_IPropertySetStorage, stg);
     OleCheck(res);

     PropSetStg := Stg as IPropertySetStorage;

     open:=PropSetStg.Open(FmtID_SummaryInformation,
        STGFMT_FILE or STGM_READ or STGM_SHARE_EXCLUSIVE, PropStg); //open=-2147287038 
     OleCheck(open); // EOleSysError "%1 could not be found
     ...

On instruction OLECheck(Open) I have an EOleSysError "%1 could not be found". Open returns -2147287038

Please tell me what I'm doing wrong Article with full function code

IDE: Embarcadero® Delphi® XE Version 15.0.3890.34076

Upvotes: 2

Views: 2012

Answers (1)

Arioch 'The
Arioch 'The

Reputation: 16045

This code snippet uses STGFMT_ANY despite its prohibited status. http://forum.sources.ru/index.php?showtopic=115495

Maybe that is way to go, if it does work. (that code used before-unicode Delphi. Usual checks and simplifications of upgrading to Unicode-aware Delphi would need to be applied)

That snippet makes use of StringToOleStr instead of typecast, and since even in Delphi XE2 that function is still more than typecast stub - it might make difference.

That snippet also differentiate between files having internal properties (like DOC, XLS, MSC files) and those that only 'maybe' are wrapped into external properties by NTFS-5 in Vista. STGFMT_* constants should be different for DOC and JPEG files for example.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa380330.aspx

Upvotes: 2

Related Questions