我想通过Windows搜索索引服务读取DWG/AutoCAD文件的元数据。我正在谈论的是可以通过在Explorer中右键单击而无需打开AutoCAD即可访问的属性。通过Windows程序从MFC程序中读取文件元数据
我有一个基于MFC对话框的应用程序在Visual C++ 2005中编写,从这个应用程序我想访问给定文件的元数据(如作者,创建日期等)。这是由iFilter完成的,但它自Windows XP以来已弃用,并将在Windows 8中消失(并且LoadIFilter不在VS2005中)。现在根据我的理解,可以通过Windows搜索完成 - 如果我错了,请纠正我的错误。我发现的每个例子(包括MSDN)都显示了如何将有关自己文件的数据提供给Windows搜索索引。我需要的是知道如何向Windows Search询问给定文件的元数据。
感谢 tgwilk
编辑: 下面是我想出迄今:
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
连接字符串(构造)是
provider=Search.CollatorDSO.1;EXTENDED PROPERTIES="Application=Windows"
通过返回的ISearchQueryHelper。 和查询(querystr)是
SELECT System.Document.DateCreated FROM SystemIndex WHERE System.FileName LIKE 'filename%' AND DIRECTORY='file:C:\path\to\file'
现在的问题是,我得到一个异常:
First-chance exception at 0x77c5fc56 in fraudTest.exe: Microsoft C++ exception: CNLBaseException at memory location 0x0012d6d0..
在这条线
hr = con->Open(bconstr, NULL, NULL, 0);
随后从查询空结果(此代码来自WSQ_GetCDate):
rs->get_EOF(&eor);
while (eor != VARIANT_TRUE) { //this never executes }
令人惊讶的是SUCCEEDED(hr)
在异常后返回true。 我在哪里犯了错误,以及如何尝试找到它?
感谢 t.g.wilk
您是通过Windows Search API挖掘的吗? http://msdn.microsoft.com/en-us/library/aa965362.aspx – l33t