Click here to Skip to main content
16,005,826 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSending Windows Events from one app to another Pin
Zee man13-Nov-03 19:30
Zee man13-Nov-03 19:30 
GeneralRe: Sending Windows Events from one app to another Pin
Prakash Nadar13-Nov-03 20:08
Prakash Nadar13-Nov-03 20:08 
GeneralRe: Sending Windows Events from one app to another Pin
Antti Keskinen13-Nov-03 20:26
Antti Keskinen13-Nov-03 20:26 
GeneralRe: Sending Windows Events from one app to another Pin
Zee man16-Nov-03 9:13
Zee man16-Nov-03 9:13 
GeneralRe: Sending Windows Events from one app to another Pin
Antti Keskinen16-Nov-03 10:17
Antti Keskinen16-Nov-03 10:17 
GeneralRe: Sending Windows Events from one app to another Pin
Zee man19-Nov-03 17:46
Zee man19-Nov-03 17:46 
GeneralCreating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal13-Nov-03 18:57
percyvimal13-Nov-03 18:57 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
Antti Keskinen13-Nov-03 20:59
Antti Keskinen13-Nov-03 20:59 
First, I recommend pointing your browser to MSDN and the Win32 Hooks article[^] underneath it. Read it through carefully, because it will answer most of your questions.

If you don't understand the concepts presented in this article, then you should learn more of the functionality of Windows before attempting to create hooks. Codeproject has a collection of fine articles on the issue of hooking. These should help you get started.

Now, about using the hook. Basically, you can create the DLL on any language you please. If it is implemented correctly, you can load the DLL in VB and use a VB program to register the system wide hook. Remember here, that the actual DLL is a container, with which the hook procedure is injected to a foreign process' address space. The loader application is responsible for actually registering the hook.

As for the questions you presented, here is a set of answers.

1. For creating the container DLL, take Win32 Dynamic Link Library project.
2. The creation of a DLL is explained throughoutly in many articles here in CodeProject. Just browse, and look for articles with the level 'Beginner' marked next to them.

3. In order to call a function of a DLL from the loading application, you need to EXPORT it. See the DLL articles for examples. In short, use __declspec(dllexport) calling convention and a module definition file's EXPORTS section.

4. When you register a global hook, your DLL gets cramped into every running process' address space, and the hook is installed to the message pump of every thread on that process. So, yes, all WM_GETMESSAGE call returns will be routed through your hook procedure.

The way it works is that the hook will be the first to receive the created event message. You then process this message, and alter it the way you please, for example in a WM_CHAR message, you would change the virtual key code. Then you post the message forward in the chain list, and it will eventually end up to the thread it was meant for, this time in an altered form.

5. Like above, catch the WM_GETMESSAGE return value, see if it is a WM_CHAR message, and if it is, alter the virtual key code. If you register the hook correctly, the system will worry about it getting properly called.

For the issue questions

1. Select the appropiate project, and implement the DLL code, following any of the many articles available. There are even beginner articles available in CodeProject. If you cannot understand the concepts of these, you should go pick up a book and learn more about Win32 applications first.

2. The header file is not necessary. A DLL MUST have a DllMain-function (entry point) and one or more exported functions or shared data segments. Otherwise it is just extra baggage with nothing useful.

3. To declare an exported function, use __declspec(dllexport) calling convention or a module definition file. See MSDN, search with the __declspec keyword.

4. The hook's working is explained in the MSDN article I posted a link to above. Refer to it for more details.

5. #pragma is a preprocessor definition which can be used to issue commands to the MSVC compiler. In a standard hook DLL, you don't need shared data sections, thus, you don't need #pragma.

When answering, please take some time to formulate and type-check your posts. It is much more convinient to read and answer your questions when they are easy to understand and the points you're after are presented clearly. Use chapters, line changes, spaces, punctuation marks, everything you need to make it easier to read Smile | :)

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal13-Nov-03 23:20
percyvimal13-Nov-03 23:20 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
Antti Keskinen14-Nov-03 12:11
Antti Keskinen14-Nov-03 12:11 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal30-Nov-03 20:06
percyvimal30-Nov-03 20:06 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
Antti Keskinen30-Nov-03 23:20
Antti Keskinen30-Nov-03 23:20 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal30-Nov-03 23:29
percyvimal30-Nov-03 23:29 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal12-Dec-03 19:19
percyvimal12-Dec-03 19:19 
GeneralRe: Creating a systemwide hook dll in vc++ that can be used in vb Pin
percyvimal8-Jan-04 17:49
percyvimal8-Jan-04 17:49 
QuestionHow to create Tree view for displaying directory structure in vc++ Pin
harsh91113-Nov-03 18:35
harsh91113-Nov-03 18:35 
AnswerRe: How to create Tree view for displaying directory structure in vc++ Pin
Prakash Nadar13-Nov-03 18:50
Prakash Nadar13-Nov-03 18:50 
GeneralDynamic object creation Pin
Ravi Jadhav13-Nov-03 18:10
Ravi Jadhav13-Nov-03 18:10 
GeneralRe: Dynamic object creation Pin
Prakash Nadar13-Nov-03 21:56
Prakash Nadar13-Nov-03 21:56 
GeneralRe: Dynamic object creation Pin
Antti Keskinen13-Nov-03 22:02
Antti Keskinen13-Nov-03 22:02 
GeneralCreating a burning and circling text Pin
nhanquy8313-Nov-03 17:00
nhanquy8313-Nov-03 17:00 
GeneralCustom Control Pin
Prakash Nadar13-Nov-03 17:00
Prakash Nadar13-Nov-03 17:00 
GeneralRe: Custom Control Pin
KKR13-Nov-03 19:59
KKR13-Nov-03 19:59 
GeneralRe: Custom Control Pin
Prakash Nadar13-Nov-03 21:28
Prakash Nadar13-Nov-03 21:28 
QuestionHow can I crack an encryped-zip file or a encrypted Word document? Pin
earthquake_cui13-Nov-03 16:30
earthquake_cui13-Nov-03 16:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.