微软的桌面搜索API推出也有一段时间了,但是网上可以找到的相关技术资料还不多。官方的资料在http://addins.msn.com/devguide.aspx可以看到,而且网页上有SDK和一个C#的示例供下载。
使用搜索API非常的简单,首先创建一个桌面搜索对象
BOOL CWDSSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if(m_pSearchDesktop.CreateInstance(CLSID_SearchDesktop))
{
AfxMessageBox(IDS_FAILED_TO_CREATE_SEARCH_ENGINE);
return FALSE;
}
……
之后就可以开始执行搜索了。桌面搜索对象有两个方法,ExecuteSQLQuery和ExecuteQuery,都返回一个ADO记录集对象。ExecuteQuery是对用户比较友好的版本,参数虽然比较多,但是不需要自己构建SQL;而ExecuteSQLQuery是底层版本,只有一个参数——需要自己构造的SQL。相信我,你不会渴望自己来创建SQL的。传递给ExecuteQuery的参数就已经够长的了。字符串表中IDS_COLUMNS_GENERAL的内容是:
DocTitle,DocFormat,Url,DocAuthor,PrimaryDate,FileName, FileExt,IsAttachment,Characterization,Rank,PerceivedType, HasAttach,DocTitlePrefix,FileExtDesc,DisplayFolder, DocKeywords,DocComments,ConversationID,Size, Create,Write。
void CWDSSampleView::Search(LPCTSTR lpszQuery,LPCTSTR lpszSort)
{
CString strQuery(lpszQuery);if(strQuery.IsEmpty())return;
CString strSort(lpszSort);
USES_CONVERSION;
HRESULT hr=S_OK;
GetListCtrl().SetItemCount(0);
ClearCache();
try{
CString strColumns;
VERIFY(strColumns.LoadString(IDS_COLUMNS_GENERAL));
if(strSort.IsEmpty())
m_pRecordset=m_pSearchDesktop->ExecuteQuery(T2OLE(strQuery),
T2OLE(strColumns),NULL,NULL);
else
m_pRecordset=m_pSearchDesktop->ExecuteQuery(T2OLE(strQuery),
T2OLE(strColumns),T2OLE(strSort),NULL);
int nItemCount=m_pRecordset->GetRecordCount();
GetListCtrl().SetItemCount(nItemCount);
}
catch(_com_error&e)
{
……
}
}

但是,访问返回的记录集的速度比访问数据库要慢。我不得不用虚列表和缓存来提高性能。在搜索结果很多(例如关键字选择"Microsoft")时程序有假死现象——当然也不排除我选择的字段过多的原因。
最近在写一个14位CPU的模拟器,CPU指令长度是固定的——13字节,十分的不吉利^_^b,而且CPU指令集中一些特定指令会根据上下文判断是否跳过下一个指令。但是在Intel系统上没有这样的指令,而且指令长度是可变的,所以无法知道下一个指令的长度来跳过它。我现在是在内存中设置一个标志,在执行每个指令之前检查这个标志来判断前一个指令是否指明跳过当前指令——低效,但是可以正常工作。
现在我知道一些模拟器为什么慢得像乌龟爬了……
使用WinDbg调试VC程序
虽然在VC6.0中可以通过安装Visual C++ Toolkit(网站:http://msdn.microsoft.com/visualc/vctoolkit2003/)来编写基于最新版本的平台SDK、DirectX SDK的程序以及托管代码,但是VC6附带的调试器并不支持新版本的调试信息,所以实际上是不能用VC6来调试新版本编译器生成的程序的。一个替代的解决方案是使用新版本的Windows调试工具Windbg(网站:http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx)。Windbg的调试功能基本和Visual C++中的相同,但是需要手动设定源文件和调试符号文件的搜索路径(可以参考VC6.0中的对应设置)。一些代码,例如MFC的代码比较难于定位,这时可以双击调用堆栈中的函数名称来打开文件并定位到函数所在位置。Windbg可以进行有限的托管代码调试,但是调试过程比较麻烦。在没有安装Visual Studio的计算机上调试,例如进行远程调试的时候可能还需要部署调试符号(Generating and Deploying Debug Symbols With Visual C++ 6.0)。
调试Visual Studio .Net 的程序需要用户是管理员或者"Debug User"用户组成员。如果登录用户不是该组成员,那么也可以用WinDbg来调试程序。
由于BSTR经常会当OLESTR用,有时候就把它们的区别搞忘记了
今天查一个Debug通过Release崩溃的问题查了半天,最后发现是把OLESTR当BSTR用了
CComPtr pRecvDocument;
if(!m_wndRecv.GetDHtmlDocument(&pRecvDocument))return;
if(pRecvDocument==NULL)return;
//pRecvDocument->createElement(L"p",&pNewElement);这行出错
pRecvDocument->createElement(CComBSTR("p"),&pNewElement);//这行通过
以后要当心。
P.S.按理说Debug和Release方式下IHTMLDocument2的createElement行为应该相同才是,但是事实是不同……
Windows Multimedia API ICConfigure可以通知视频编码程序显示它的配置对话框。对于有经验的用户,这工作的很好。但是对于不了解视频编码程序的用户,面对一大堆鸟语设置肯定会晕头转向。
但是我只需要简单的设置带宽就可以了。
手头没有XVID的接口,所以用了类似修改游戏的方法来找到带宽设置在压缩参数中的地址
??HIC hic = ICOpen(compressor_info[sel].fccType, compressor_info[sel].fccHandler, ICMODE_QUERY);??
??if (hic) {???
???
???//Set our current Video Compress State Info into the hic, which will update the ICConfigure Dialog
#ifdef?_DEBUG
???DWORD statesize = ICGetStateSize(hic);
???LPBYTE?lpOldStart=NULL;
???if(pVideoCompressParams){
????lpOldStart=new BYTE[statesize];
????memcpy(lpOldStart,pVideoCompressParams,statesize);
???}
#endif???
???SetVideoCompressState (hic , compressor_info[sel].fccHandler);???
???ICConfigure(hic,m_hWnd);???
???//Get Video Compress State Info from the hic after adjustment with the ICConfigure dialog
???//This will set the external pVideoCompressParams variable which is used? by AVICOMPRESSOPTIONS
???//(This means the external variable pVideoCompressParams will be changed even if user press "Cancel")
???GetVideoCompressState (hic , compressor_info[sel].fccHandler);???
???
???ICClose(hic);
#ifdef?_DEBUG
???if(lpOldStart){
????LPBYTE lpNewStart=(LPBYTE )pVideoCompressParams;
????for(int i=0;i?????if(lpOldStart[i]!=lpNewStart[i]){
??????TRACE("State bit #%d\tfrom %x \tto %x\r\n",i,lpOldStart[i],lpNewStart[i]);
?????}
????}
????delete[]?lpOldStart;
????lpOldStart=NULL;
???}???
#endif
检查到XVID的带宽设置是在其参数的第4-6字节,单位是bps。
下面的工作就简单了,直接修改获得的压缩参数的这个部分,用ICSetState设置就行了
没想到修改游戏的方法居然可以这样用……
创建一个win32DLL工程,从DXSDK示例Ball复制代码之后就出这个问题
Deleting intermediate files and output files for project 'FScrCap - Win32 Debug'.
--------------------Configuration: FScrCap - Win32 Debug--------------------
Compiling...
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright
Microsoft Corp 1984-1998. All rights reserved.
cl? /MTd /Ze /W3 /Gm /Gi /GR- /GX /ZI /Od /D WIN32 /D _DEBUG /D _WINDOWS /D _MBCS /D _USRDLL /D FSCRCAP_EXPORTS /FpDebug/FScrCap.pch /Ycstdafx.h /FoDebug/ /FdDebug/ /FD /GZ /c F:\code\test\DirectShow\FScrCap\StdAfx.cpp
StdAfx.cpp
Compiling...
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright
Microsoft Corp 1984-1998. All rights reserved.
cl? /MTd /Ze /W3 /Gm /Gi /GR- /GX /ZI /Od /D WIN32 /D _DEBUG /D _WINDOWS /D _MBCS /D _USRDLL /D FSCRCAP_EXPORTS /FpDebug/FScrCap.pch /Yustdafx.h /FoDebug/ /FdDebug/ /FD /GZ /c F:\code\test\DirectShow\FScrCap\fBall.cpp F:\code\test\DirectShow\FScrCap
\FScrCap.cpp
fBall.cpp
FScrCap.cpp
Generating Code...
Linking...
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol ___security_cookie
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol ___security_cookie
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol ___security_cookie
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol ___security_cookie
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol ___security_cookie
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
strmbasd.lib(wxlist.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(source.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(combase.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(amvideo.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol @_RTC_CheckStackVars@8
strmbasd.lib(amvideo.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(wxlist.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(source.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(combase.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(mtype.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol __RTC_CheckEsp
strmbasd.lib(amvideo.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(wxlist.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(source.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(combase.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(mtype.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol __RTC_Shutdown
strmbasd.lib(amvideo.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(wxlist.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(source.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(combase.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(mtype.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(amfilter.obj) : error LNK2001: unresolved external symbol __RTC_InitBase
strmbasd.lib(wxutil.obj) : error LNK2001: unresolved external symbol __RTC_UninitUse
Debug/FScrCap.dll : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.
FScrCap.dll - 51 error
, 0 warning
To use it from Visual Studio 6 a replacement .LIB is needed that can be found in the Extra's that can be downloaded from Microsoft.
http://msdn.microsoft.com/directx/directxdownloads/
or you can replace the compiler of VC6 with the VC2003 compiler
http://www.csdn.net/develop/read_article.asp?id=21702
最近这篇文章长长短短,写了两个礼拜吧。
写这篇文章的主要原因是想把网页分析做得更加灵活。这篇文章的基础是我以前为一个EBS游戏写的外挂,可以自动修改网页内容(主要是表单)和定时submit表单(有的网站的submit有时间限制)。以前的代码是用VC来写的,和网页的修改同步很不方便。很多功能,例如表单的自动填写和递交依赖于表单的结构,网页结构一变的话,就需要重新编译代码。所以这次重写的时候(那个EBS又改版了),想考虑做成类似于Outlook的邮件规则。但是在编写的时候,发现这样的规则编写起来实在是太繁琐了。其实这些规则用VB来写脚本的话,可能就几句话,例如判断浏览完成之后判断URL,自动填写和递交表单。
这是我使用VBS的原因。在程序中集成脚本解释器之后,网站改版的时候改脚本就可以了,虽然使用门槛要高些(要会编写脚本)。
主要碰见的技术问题是
脚本中的浏览器的事件处理代码不能执行(CHtmlView捕获了事件,所以要在CHtmlView里面转发事件)
移植MFCIE的代码到MDI的时候的菜单出现很多问题,主要是MDI的菜单替换,以及插入MDI系统菜单之后收藏夹的位置变化
移植部分MFC7的代码到MFC6,中间还结合了一大堆修复MFC6BUG的代码,真是faint
无法直接创建支持事件的CCmdTaget类(ActiveX好像可以……)
MFC的类向导不支持自动化中的默认参数
上面两个问题使得我不得不手动改ODL文件,结果造成无数问题……ODL还是能不改就不改吧
关闭窗口时出现非法操作(最后捕获了WindowClosing事件,Cancel掉了系统的处理之后自己关闭)
调用IE的表单的自动完成的时候,没做成功。好像和隐藏方法IShellUIHelper::AutoCompleteAttatch有关。
编辑网页源代码时文档结构的刷新有问题,被编辑的节点的Child集合在SetOutHTML之后长度变成0了,最后是刷新整个文档结构树才解决。IE的BUG?