首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用IFilter C++获取OLE属性

使用IFilter C++获取OLE属性
EN

Stack Overflow用户
提问于 2014-08-08 09:51:04
回答 1查看 448关注 0票数 1

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

代码语言:javascript
复制
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获得相同的解决方案。

谢谢阿洛特!希望你能找到答案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-08 12:59:05

该值在STAT_CHUNK's attribute字段中定义。它被定义为FULLPROPSPEC结构,它可以(大多数情况下)与Windows属性系统直接相关。

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

例如,这是一个示例代码,它能够确定使用PSGetNameFromPropertyKeyIPropertyDescription:FormatForDisplay格式化为字符串的属性名称和值:

代码语言:javascript
复制
...
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);
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25200636

复制
相关文章

相似问题

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