Objective
This article (in fact, essay) and the description of the example code mainly includes: API interception, message hooks, Enum subform, registry system hotkey. Where the message hook, API interception, enumeration subform implementation code in the DLL, registration system hotkey code implementation in the test EXE, the other EXE snippet also involved in custom messages and system bar icons. I hope it works for you.
A year has passed, still the same as the old-to live, for money and busy. Fortunately, the body is quite healthy, eat well, sleep soundly:-) hope that the new year will be a bit more drum. Today, the hard drive, found the code, back when I began to write as if still in the Vckbase forum raised some questions, but also got a lot of friends of the Forum's enthusiastic help, thanks here. Originally want to write a good experience, especially can let VC beginners to learn something. But their language skills too bad, can only think of where to write. I hope you enjoy tea, while surfing the internet, one-hand chat, a reply, left to see PP, the right eye can adhere to read the following characters.
The reason to write this program: initially because the customer's needs are not very obvious, just said that his database program data for a temporary deception to cope with the inspection (who did not know the inspection, ha, let me write cheating procedures, test me na), the only requirement is not to change the real data. I actually compare a headache database, want to not study his database structure, thought to adopt a more lazy way to realize on the line. September, I was also very idle, online crazy after a pass, basically decided to use the screen word to do the way. is to intercept the data displayed on the screen, as long as it's a numeric type, multiply by a cardinal, and then write the data back to the screen. In fact, this screen to pick up the word technology online early, I also just want to practice practicing. Write almost the time, vomiting blood when it is, the customer requirements in addition to temporary deception, but also to display the data on the spot with the original program Print button. I was dumbfounded, so also abandoned this method, vomited a pass of blood, hold a ventilation, honest study of the original program database structure, fortunately is the SQL Server 2K, had been, and finally rushed to the inspection before the live.
Carelessly said so much nonsense. All right, go to the point. The following separate ways to:
Intercepting API (or intercepting API anyway)
First of all, the interception API, in the HOOKAPI.h and CPP files, this is a traditional version. There are many versions on the Internet, and I think this is a little bit simpler (long live). The original author does not know is Taiwan or Hong Kong, the annotation uses the BIG5 code. The interception API is generally a few steps:
Obtain the function address (GetProcAddress), obtain the address of the function being intercepted and replace the address of the intercepted function (i.e. the function to be processed after intercepting);
form the jmp instruction (__asm), ready to avoid the intercepted function to jump to the processing function directly processing;
Set memory writable (virtualprotect), the function of the jump after the execution;
Remember to restore memory.
There are a lot of tutorials on the Internet about API interception, but I don't know how to say it anyway. In fact, my understanding is very simple, is to find ways to open the boss's office, sneak in, and then replace the bonus sheet, and then close the door, leave ... It's as simple as that. Note that there are three: one is the original function of the address, in which DLL, do not check the wrong; one is to replace the parameters of the function, you must follow the rules of the game, what type of what type, the other is the memory of the reading and writing sequence, can not leak can not reverse. You can refer to the HOOKAPI Code section, here is not post.
Hooks (Hook)
About the message hook, in fact, two words: SetWindowsHookEx, UnhookWindowsHookEx, loading hooks and unloading hooks, but also on these two words, learn to write hooks, toss for a while. A suggestion for beginners: Understand the death of the message mechanism, temporarily put down MFC, try to write at least one SDK program, before you write, take a good look at MSDN, a lot of questions can be answered here. SetWindowsHookEx has four parameters, mainly attention to 1 and 4 of these two parameters, the first parameter recommended less wh_callwndproc unless you have to do so. In general, there are messages, keyboard and mouse hooks are sufficient, of course, except in exceptional circumstances.