Leggi i metadati dei file tramite la ricerca di Windows dal programma MFC
-
13-12-2019 - |
Domanda
Vorrei leggere i metadati di un file DWG / AUTOCAD tramite il servizio di indicizzazione della ricerca di Windows. Sto parlando di proprietà a cui è possibile accedere con il tasto destro in Explorer senza aprire AutoCAD.
Ho un'applicazione basata sulla finestra di dialogo MFC scritta in Visual C ++ 2005 e dall'interno di questa app vorrei accedere ai metadati (come l'autore, la data di creazione ecc.) del file specificato. Questo è stato fatto da IFILTER ma è deprecato da Windows XP e sarà andato in Windows 8 (e LoabileFilter non è presente in VS2005). Ora da quello che capisco, può essere fatto con Windows Search: correggimi se sbaglio. Ogni esempio ho trovato (MSDN incluso) mostra come fornire dati sui propri file alla ricerca di Windows per l'indicizzazione. Quello di cui ho bisogno è sapere come chiedere la ricerca di Windows sui metadati per un determinato file.
Grazie t.g.wilk
Modifica: Ecco cosa ho trovato finora:
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
.
La stringa di connessione (constring) è
provider=Search.CollatorDSO.1;EXTENDED PROPERTIES="Application=Windows"
.
Come restituito da ISearchQueryhelper. E la query (Querystr) è
SELECT System.Document.DateCreated FROM SystemIndex WHERE System.FileName LIKE 'filename%' AND DIRECTORY='file:C:\path\to\file'
.
Il problema ora è che ottengo un'eccezione:
First-chance exception at 0x77c5fc56 in fraudTest.exe: Microsoft C++ exception: CNLBaseException at memory location 0x0012d6d0..
.
su questa riga
hr = con->Open( bconstr, NULL, NULL, 0 );
.
seguito dal risultato vuoto dalla query (questo codice è da wsq_getcdate):
rs->get_EOF( &eor );
while ( eor != VARIANT_TRUE ) { //this never executes }
.
SUCCEEDED(hr)
sorprendente restituisce il vero dopo l'eccezione.
Dove ho fatto errori e come provare a trovarlo?
Grazie t.g.wilk
Soluzione
Non ho risolto questo particolare problema, ma ho imparato che non ho bisogno di una ricerca di Windows per ottenere i metadati del file.La parola chiave da cercare è "Proprietà" anziché i meta-dati.Ho ricevuto il mio pezzo di codice da Windows SDK V7.0 Applicazione di esempio denominata Propertyedit.