首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取文件摘要信息时出现的问题

提取文件摘要信息时出现的问题
EN

Stack Overflow用户
提问于 2012-08-24 19:12:12
回答 1查看 1.8K关注 0票数 2

我为我的英语道歉,它不好,但我希望你能理解我的问题。我对WinAPI函数StgOpenStorageEx的使用有问题。我需要获取文件的摘要信息。我找到了一些解决方案,但在所有这些解决方案中,我都需要使用StgOpenStorageEx。因为它不在标准模块中,所以我自己将其声明为从ole32.dll导出,如下所示

代码语言:javascript
复制
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';   

接下来,我需要像这样使用这个函数

代码语言:javascript
复制
    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
     ...

在指令OLECheck(Open)上,我有一个EOleSysError "%1找不到“。Open返回值-2147287038

请告诉我我做错了什么Article with full function code

IDE: Embarcadero®Delphi®XE版本15.0.3890.34076

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-24 20:24:45

此代码段使用STGFMT_ANY,尽管它处于禁止状态。http://forum.sources.ru/index.php?showtopic=115495

也许这是一条可行的道路,如果它真的有效的话。(之前使用的代码-unicode Delphi。需要应用升级到支持Unicode的Delphi的常规检查和简化)

该代码片段使用StringToOleStr而不是类型转换,因为即使在Delphi XE2中,该函数仍然不仅仅是类型转换存根-它可能会有所不同。

该代码片段还区分了具有内部属性的文件(如DOC、XLS、MSC文件)和那些仅由Vista中的NTFS-5包装成外部属性的文件。例如,对于DOC和JPEG文件,STGFMT_*常量应该不同。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12108295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档