|
|
14 Sep 2009 07:50:01 am |
Hook原来是这样工作的 |
|
|
先用自己的exe装载含有自己hook代码的dll(可以用loadlibrary,或者静态直接启动装入这个dll)再在自己的exe调用一个SetWindowsHookEx,SetWindowsHookEx可以设定为对所有的mouse hook,而proc参数就是上面dll中的proc.
这样SetWindowsHookEx会在系统所有用到mouse的新启动的进程里都会loadlibrary装入自己的hook dll。
在自己hook dll的Dllmain里可以判断目前的进程是哪个exe,或dll,如果发现是自己想要hook的那个进程.就可以进一步修改这个进程的内存,可以修改它的import table使其在调用系统api时先调用我们的。也可以检索它的内存,找到特定的内部函数,在调用这些函数前先调用我们自己的函数.
这里比较让人吃惊的是,实际上SetWindowsHookEx后,对每个进程实际上系统回自动loadlibrary你自己
的hook dll,导致你的Dllmain每次都会被调用. |
|
| |
Category : Windows API
| Posted By : Eric Shan | Comments[0] | Trackbacks [0] |
|
|
|
12 Apr 2009 02:10:47 am |
Win32 picture process function |
|
|
http://www.codeproject.com/KB/winsdk/win32image.aspx |
|
| |
Category : Windows API
| Posted By : Eric Shan | Comments[0] | Trackbacks [0] |
|
|
|
20 Oct 2008 09:42:21 am |
Get print result from SQL statement |
|
|
Some of my colleague is lazy, and create the report in SQL and refuse to create an interface for user to execute the SQL. The SQL looks like below. The 'print' make the result in the SQL server management message window. So I'm thinking to make an interface but I do not want to change the SQL, so that is mean I need to get the result from the 'print'. The google told me it is possible to create it through register an call back fuction is CS, but I want an C++ interface. So I finally find ODBC can do it.
Code : Set @DueFromPBOC =(Select isnull(sum(isnull(ac.AccountBalance,0)),0) From View_Account_Log ac
Print 'Result = '+ Convert(varchar(50), @DueFromPBOC)
The process is just like below,
SQLAllocEnv
SQLAllocConnect
SQLConnect
SQLPrepare
SQLExecute
after that, using SQLGetDiagRec to find out the result from the SQL 'print'
Code :
i=1;
while ((rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError,
Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA)
{
//DisplayError(SqlState,NativeError,Msg,MsgLen);
//printf("%s, %srn",SqlState, Msg);
printf("%srn",Msg);
i++;
// }
}
There are two points here,
1. The SQL sentence must have an zero (0x0) end, to let SQL server know the end of the sentense
2. Must use SQLExecute instead of SQLExecDirect, SQLExecDirect can not reture the entired message, and only reture first part if you have several select statement in one batch. |
|
| |
Category : Windows API
| Posted By : Eric Shan | Comments[0] | Trackbacks [0] |
|
|
|
28 Nov 2007 07:27:59 am |
VC VS2005 Link出的EXE居然要额外的Dll支持,都是winsxs惹的祸 |
|
|
vc vs2005, LINK 了一个简单的dos console的exe, 在本机上运行没有问题,但在没有装VS2005的机器上报错: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem
结果解决的办法是把VS2005下的两个文件考到和主程序同一目录下:
C:\Program FilesMicrosoft Visual Studio 8VCredistDebug_NonRedistx86Microsoft.VC80.DebugCRT
msvcr80d.dll
Microsoft.VC80.DebugCRT.manifest
至于winsxs, 可以参考:
http://davidlenihan.com/2007/07/winsxs.html
http://msdn2.microsoft.com/en-us/library/aa376307.aspx
http://msdn2.microsoft.com/EN-US/library/aa369532.aspx
English Version:
I linked a simple DOS(Console)exe, running in my PC is fine, but when copy to others PC, it reports error of:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem
The solution is copy two files from VS2005 to the same path of your exe:
C:\Program FilesMicrosoft Visual Studio 8VCredistDebug_NonRedistx86Microsoft.VC80.DebugCRT
msvcr80d.dll
Microsoft.VC80.DebugCRT.manifest
The winsxs is the reason of it, for detail see:
http://davidlenihan.com/2007/07/winsxs.html
http://msdn2.microsoft.com/en-us/library/aa376307.aspx
http://msdn2.microsoft.com/EN-US/library/aa369532.aspx |
|
| |
Category : Windows API
| Posted By : Eric Shan | Comments[0] | Trackbacks [0] |
|
|
|
05 May 2007 02:10:10 pm |
ListView排序新特性 |
|
|
在codeproject(http://www.codeproject.com/cpp/ListCtrlSort.asp)上看到这样一篇文章,大致是说在XP下,ListView的排序是:
sort1
sort2
sort10
sort20
而不再是
sort1
sort10
sort2
sort20
这很好啊,但是作者说不清楚如何可以在自己的app中达到这个效果.于是作者用LVM_SORTITEMSEX加上自己的sort function来达到这个效果. 这个sort function当然有点复杂.所以在评论中MVP建议使用StrCmpLogicalW来做sort的工作.这个StrCmpLogicalW是只在XP以上版本,而且只有Unicode. |
|
| |
Category : Windows API
| Posted By : Eric Shan | Comments[0] | Trackbacks [0] |
|
|
|
1 |
|