gpt4 book ai didi

c++ - 使用 IFilter C++ 获取 OLE 属性

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:50 32 4
gpt4 key购买 nike

我一直在使用 IFilter COM 对象从文件中提取文本。我设法提取了 OLE 属性(例如作者的值(value)、公司的值(value)等),但我不知道如何知道哪个值是作者、公司等。

CoInitialize(NULL);
IFilter *pFilt;
HRESULT hr = LoadIFilter( L"c:\\bla.docx", 0, (void**)&pFilt );
if ( FAILED( hr ) )
{
cout<<"Bla"<<endl;
}

ULONG flags;
hr = pFilt->Init( IFILTER_INIT_APPLY_INDEX_ATTRIBUTES, 0, 0, &flags );
if ( FAILED( hr ) )
{
cout<<"Bla"<<endl;
}
if(flags == 1)
{
cout<<"With OLE!"<<endl;
}
STAT_CHUNK chunk;
while ( SUCCEEDED( hr = pFilt->GetChunk( &chunk ) ) )
{
if ( CHUNK_TEXT == chunk.flags )
{
WCHAR awc[100];
ULONG cwc = 100;
while ( SUCCEEDED( hr = pFilt->GetText( &cwc, awc ) ) )
{
cout<<awc<<endl;
// process the text buffer.&nbsp;.&nbsp;.
}
}
else // CHUNK_VALUE
{
PROPVARIANT *pVar;
while ( SUCCEEDED( hr = pFilt->GetValue( &pVar ) ) )
{

**// Right here, i can see the value of pVar is the correct author, but i dont know how to tell this is the author, or the company etc..**
PropVariantClear( pVar );
CoTaskMemFree( pVar );
}
}

}

换句话说,我需要知道什么是属性 id,并将其与属性的值相匹配。

我见过使用 IPropertyStorage->ReadMultiple 的解决方案,但我正在尝试使用 IFilter 获得相同的解决方案。

非常感谢!希望您能找到答案。

最佳答案

该值在 STAT_CHUNK 的 attribute 字段中定义。它被定义为一个 FULLPROPSPEC 结构,它可以(大部分时间)直接与 Windows Property System 相关。 .

FULLPROPSPEC 可以指向 GUID+id 属性,或指向由其名称定义的自定义属性(理想情况下,您需要检查 psProperty.ulKind 以确定这一点)。今天,大多数实现只是不使用名称,而是坚持“属性”的 GUID(属性集)+ PROPID(整数)定义。

因此,例如,这是一个示例代码,能够使用 PSGetNameFromPropertyKey 确定格式为字符串的属性名称和值是什么。和 IPropertyDescription::FormatForDisplay :

...
if (CHUNK_VALUE == chunk.flags)
{
if (chunk.attribute.psProperty.ulKind == PRSPEC_PROPID)
{
// build a Windows Property System property key
// need propsys.h & propsys.lib
PROPERTYKEY pk;
pk.fmtid = chunk.attribute.guidPropSet;
pk.pid = chunk.attribute.psProperty.propid;
PWSTR name;
if (SUCCEEDED(PSGetNameFromPropertyKey(pk, &name)))
{
wprintf(L" name:'%s'\n", name);
CoTaskMemFree(name);
}

IPropertyDescription *pd;
if (SUCCEEDED(PSGetPropertyDescription(pk, IID_PPV_ARGS(&pd))))
{
PROPVARIANT *pVar;
hr = pFilt->GetValue(&pVar);
if (SUCCEEDED(hr))
{
LPWSTR display;
if (SUCCEEDED(pd->FormatForDisplay(*pVar, PDFF_DEFAULT, &display)))
{
wprintf(L" value:'%s'\n", display);
CoTaskMemFree(display);
}
PropVariantClear(pVar);
}
pd->Release();
}

continue;
} // otherwise it's a string

PROPVARIANT *pVar;
hr = pFilt->GetValue(&pVar);
if (SUCCEEDED(hr))
{
// do something with the value
PropVariantClear(pVar);
}
}

关于c++ - 使用 IFilter C++ 获取 OLE 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25200636/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com