Question

I would like to read metadata of a DWG/AutoCAD file via Windows Search indexing service. I'm talking about properties that can be accessed with the right click in explorer without opening 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. 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). Now from what I understand, it can be done with windows search - correct me if I'm wrong. Every example I found (msdn included) shows how to give data about your own files to windows search for indexing though. What I need is to know how to ask Windows Search about metadata for a given file.

Thanks t.g.wilk

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

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

as returned by ISearchQueryHelper. And the query (querystr) is

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):

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

Suprisingly SUCCEEDED(hr) returns true after the exception. Where have I made en error and how to try and find it?

Thanks t.g.wilk

Was it helpful?

Solution

I didn't solve this particular problem, but I learned that I don't need Windows Search to get the file metadata. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top