简体   繁体   English

通过MFC程序通过Windows搜索读取文件元数据

[英]Read file metadata via Windows Search from MFC program

I would like to read metadata of a DWG/AutoCAD file via Windows Search indexing service. 我想通过Windows搜索索引服务读取DWG / AutoCAD文件的元数据。 I'm talking about properties that can be accessed with the right click in explorer without opening AutoCAD. 我说的是可以在浏览器中右键单击而无需打开AutoCAD即可访问的属性。

I have an MFC dialog based application written in Visual C++ 2005 and from inside this app I would like to access metadata (such as author, creation date etc.) of the given file. 我有一个用Visual C ++ 2005编写的基于MFC对话框的应用程序,从这个应用程序内部,我想访问给定文件的元数据(例如作者,创建日期等)。 This was done by iFilter but it is deprecated since Windows XP and will be gone in Windows 8 (and LoadIFilter is not present in VS2005). 这是由iFilter完成的,但自Windows XP以来已弃用,它将在Windows 8中消失(并且VS2005中不存在LoadIFilter)。 Now from what I understand, it can be done with windows search - correct me if I'm wrong. 现在,据我了解,这可以通过Windows搜索完成-如果我错了,请纠正我。 Every example I found (msdn included) shows how to give data about your own files to windows search for indexing though. 我发现的每个示例(包括msdn)都显示了如何将有关自己文件的数据提供给Windows搜索索引。 What I need is to know how to ask Windows Search about metadata for a given file. 我需要知道如何询问Windows Search有关给定文件的元数据。

Thanks tgwilk 谢谢tgwilk

EDIT: Here's what I've come up with so far: 编辑:这是到目前为止我想出了什么:

BOOL WSQ_DoQuery( const wchar_t *constr, const wchar_t *querystr, VARIANT &result ) {

    HRESULT hr = 0;

    BOOL ret;
    // Get the ADO connection
    _Connection *con = NULL;
    hr = CoCreateInstance( CLSID_Connection, NULL, CLSCTX_ALL, IID__Connection, (LPVOID *)&con );
    if ( SUCCEEDED(hr) ) {

        _Recordset *rs = NULL;

        // Convert wide strings to BSTR as required by ADO APIs
        BSTR bconstr = SysAllocString( constr );
        BSTR bquerystr = SysAllocString( querystr );

        if ( bconstr && bquerystr ) {

            // Open the connection
            hr = con->Open( bconstr, NULL, NULL, 0 );
            if ( SUCCEEDED(hr) ) {

                // Execute the query
                hr = con->Execute( bquerystr, NULL, 0, &rs );
                if ( SUCCEEDED(hr) ) {

                    // Display the results
                    ret = WSQ_GetCDate( rs ,result);
                    rs->Release();

                } else {
                    TRACE( "Failed to execute query, %08x\r\n", hr );
                }   // if
            } else {
                TRACE( "Failed to open ADO connection, %08x\r\n", hr );
            }   // if

        } else {
            TRACE("Failed to convert wide to BSTR\r\n" );
        }   // if

        con->Release();
        if ( bconstr ) {
            SysFreeString( bconstr );
        }
        if ( bquerystr ) {
            SysFreeString( bquerystr );
        }
    } else {
        TRACE("Failed to get connection, %08x\r\n", hr );
    }   // if
    return ret;
}   // DoQuery

The connection string (constr) is 连接字符串(constr)为

provider=Search.CollatorDSO.1;EXTENDED PROPERTIES="Application=Windows"

as returned by ISearchQueryHelper. 由ISearchQueryHelper返回。 And the query (querystr) is 而查询(querystr)是

SELECT System.Document.DateCreated FROM SystemIndex WHERE System.FileName LIKE 'filename%' AND DIRECTORY='file:C:\path\to\file'

The problem now is that I get an exception: 现在的问题是我得到一个例外:

First-chance exception at 0x77c5fc56 in fraudTest.exe: Microsoft C++ exception: CNLBaseException at memory location 0x0012d6d0..

on this line 在这条线上

hr = con->Open( bconstr, NULL, NULL, 0 );

followed by the empty result from the query (this code is from WSQ_GetCDate): 随后是查询的空结果(此代码来自WSQ_GetCDate):

rs->get_EOF( &eor );
while ( eor != VARIANT_TRUE ) { //this never executes }

Suprisingly SUCCEEDED(hr) returns true after the exception. 令人惊讶的是, SUCCEEDED(hr)在异常之后返回true。 Where have I made en error and how to try and find it? 我在哪里犯了错误,以及如何尝试找到它?

Thanks tgwilk 谢谢tgwilk

I didn't solve this particular problem, but I learned that I don't need Windows Search to get the file metadata. 我没有解决此特定问题,但了解到我不需要Windows Search即可获取文件元数据。 The keyword to look for is "properties" instead of meta-data. 要查找的关键字是“属性”,而不是元数据。 I got my piece of code from Windows SDK v7.0 sample application named PropertyEdit. 我从Windows SDK v7.0示例应用程序(名为PropertyEdit)获得了代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM