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

Delphi 提取文件摘要信息时出现问题,delphi,winapi,delphi-xe,Delphi,Winapi,Delphi Xe,很抱歉我的英语不好,但我希望你能理解我的问题。我在使用WinAPI函数时遇到问题StgOpenStorageEx。我需要得到文件的摘要信息。我找到了一些解决方案,但在所有这些解决方案中,我都需要使用StgOpenStorageEx。因为它不在标准模块中,所以我自己声明它是从ole32.dll导出的,如下所示 function StgOpenStorageEx ( const pwcsName : POleStr; //Pointer to the path of the

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

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';   
    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
     ...
接下来我需要像这样使用这个函数

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';   
    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(打开)
中,我有一个EOleSysError“%1”找不到。
Open
返回-2147287038

请告诉我我做错了什么


IDE:Embarcadero®Delphi®XE版本15.0.3890.34076

此代码段使用STGFMT\u ANY,尽管其处于禁止状态。

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

该代码段使用StringToOleStr而不是typecast,因为即使在Delphi XE2中,该函数也不仅仅是typecast存根,这可能会有所不同

这段代码还区分了具有内部属性的文件(如DOC、XLS、MSC文件)和那些仅“可能”被Vista中的NTFS-5包装到外部属性中的文件。例如,DOC和JPEG文件的STGFMT_*常量应该不同


1)文件名的值是多少?2) 调用OleCheck之前,StgOpenStorageEx的值是多少?3) 是否将StgOpenStorageExA或StgOpenStorageExW导入?1)文件名存储文件peth到现有(100%)文件中。我需要从该文件中获取摘要我不喜欢“%1”请务必演示如何声明文件名以及如何为其赋值。另外,请添加标签显示您的德尔福版本。这可能很重要。放弃关于nameA或nameW的第三个问题-似乎对OLE1)FileName不适用将filepeth存储到现有(100%)文件。我需要从这个文件中获取摘要。2) 返回0 3)据我所知,我只导入了stgopenstoragex,可能我错了…请确实显示您在哪里声明文件名以及在哪里分配其值的确切来源。请编辑您的问题,并添加一个标签,显示所使用的确切的Delphi版本。@Alax_rosh:tektips片段来自我:)。Arioch对STGFMTèU的任何评论都很在行。刚刚在XE上测试了这个,它可以工作+1是的!=)我从博士那里得到了总结道具。但这只是第一步=(根据任务,我需要从很多文件类型中获取道具(.doc,仅限于其中的大多数)无论如何,非常感谢大家,这段代码会问系统文件是否有内部属性。如果没有,它会尝试外部属性。只是它们的存在没有任何保证。你的程序也应该准备好处理没有属性的文件。///尽管我不知道为什么SringTool会保留,除非有人证明这一点在所有和所有可能的环境中,它都与类型转换相同,我最好使用它。OLE对我来说是一种神秘的语言,如果有函数,我最好使用它,而不是在某个陌生的用户环境中有一点点机会得到神秘的bug,我将无法复制。@Arioch'The,不足以说根据f使用正确的标志文件类型?作为一个独立的查看者,我已经阅读了34条评论,以了解问题中的代码有什么问题。很抱歉,从这个回答中我没有得到…尝试从.tif(带属性)获取道具,失败了。尝试打开文件会返回STG_E_FILENOTFOUND。我今天再也不能思考它,否则我的大脑将爆炸)此外,我国今天还有独立日。谢谢大家的帮助