提取文件摘要信息时出现问题 [英] Problems with extracting file summary information
问题描述
我很抱歉我的英语不好,但是我希望你能理解我的问题。我在使用WinAPI函数 StgOpenStorageEx
时遇到问题。我需要获取文件的摘要信息。我找到了一些解决方案,但是在所有这些解决方案中,我都需要使用 StgOpenStorageEx
。因为它不在标准模块中,所以我将它自己声明为从ole32.dll导出的
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
...
关于指令 OLECheck(Open)
我有一个EOleSysError找不到%1。
Open
返回-2147287038
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 15.0.3890.34076
IDE: Embarcadero® Delphi® XE Version 15.0.3890.34076
推荐答案
此代码段使用STGFMT_ANY,尽管其状态被禁止。
http://forum.sources.ru/index.php?showtopic=115495
This code snippet uses STGFMT_ANY despite its prohibited status. http://forum.sources.ru/index.php?showtopic=115495
也许
(该代码在unicode的Delphi之前使用。通常需要检查和简化升级为支持Unicode的Delphi)
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)
该代码段使用了 StringToOleStr 而不是typecast, d因为即使在Delphi XE2中,该功能仍然比类型转换存根还重要-它可能会有所作为。
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.
该代码段还可以区分具有内部属性(例如DOC,XLS, MSC文件)和仅可能的文件由Vista中的NTFS-5包装到外部属性中。例如,对于DOC和JPEG文件,STGFMT_ *常量应该有所不同。
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/zh-CN/library/windows/desktop/aa380330.aspx
这篇关于提取文件摘要信息时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!