C++ 使用IFilter C++;

C++ 使用IFilter C++;,c++,com,ole,ifilter,windows-search,C++,Com,Ole,Ifilter,Windows Search,我一直在使用IFilter COM对象从文件中提取文本。 我已设法提取OLE属性值(例如Author's Value、Company's Value等),但我不知道如何知道哪个值是Author、Company等 CoInitialize(NULL); IFilter *pFilt; HRESULT hr = LoadIFilter( L"c:\\bla.docx", 0, (void**)&pFilt ); if ( FAILED( hr ) ) { cout<<"B

我一直在使用IFilter COM对象从文件中提取文本。 我已设法提取OLE属性(例如Author's Value、Company's Value等),但我不知道如何知道哪个值是Author、Company等

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 );
        }
    }

}
CoInitialize(空);
IFilter*pFilt;
HRESULT hr=LoadIFilter(L“c:\\bla.docx”,0,(void**)和pFilt);
如果(失败(小时))
{

cout该值在
STAT\u CHUNK的
属性
字段中定义。它被定义为一个
FULLPROPSPEC
结构,可以(大多数情况下)直接与

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

例如,这是一个示例代码,可以使用and确定格式化为字符串的属性名称和值:

区块的属性成员应该引起您的兴趣。
...
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);
  }
}