carrythe1 0 Newbie Poster

Hi,

I am trying to learn how to use windows hooks in c++ (using visual studio 2010) and have been reading a lot of info on msdn etc. I think i have a correct understanding of the process but am unsure about some of the specifics regarding its implementation, having had limited experience using windows APIs. Specifically i've been looking at the info in:

http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx#installing_releasing

which details code used in the program running the hook and the dll that is supposed to contain the functions to return data to the main program.

What i'm trying to do is get an understanding of how to monitor the activity of another program and extract real-time data from it to feed into my own program.

I believe i understand the code on actually installing the hook (from http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx#installing_releasing):

HOOKPROC hkprcSysMsg;
static HINSTANCE hinstDLL; 
static HHOOK hhookSysMsg; 
 
hinstDLL = LoadLibrary(TEXT("c:\\myapp\\sysmsg.dll")); 
hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "SysMessageProc"); 

hhookSysMsg = SetWindowsHookEx( 
                    WH_SYSMSGFILTER,
                    hkprcSysMsg,
                    hinstDLL,
                    0);

This goes in the main program and references the sysmsg.dll file. However, the block of code starting:

#include <windows.h>
#include <strsafe.h>
#include "app.h"

#pragma comment( lib, "user32.lib") 
#pragma comment( lib, "gdi32.lib")

#define NUMHOOKS 7 
 
// Global variables 
 
typedef struct _MYHOOKDATA 
{ 
    int nType; 
    HOOKPROC hkprc; 
....
...
..
.

is troubling me. Does this go directly in the dll? I tried to set one up using this code but got a C1083 error saying the #include "app.h" file does not exist.

I have a number of questions in this area if anyone is an expert and could help me out it would be greatly appreciated:

  • When i have got the hook dll set up does it automatically send the data to my program? i.e. in int or string form? what should i expect to be recieving from the hook - a pointer to the actual memory point containing the data in the source program?
  • If the hook is set up to be systemwide does it need to keep being reloaded after every operation or does it continue to run every time the system makes a change?

A simple explanation of how i could use a hook to return data values from a page like:
http://www.google.com/finance?q=INDEXDJX:.DJI,INDEXSP:.INX,INDEXNASDAQ:.IXIC
would be great.

If anyone has any examples of a working hook extracting usable data (i.e. a constant flowing stream of numbers) from a program / web page this would be ideal in helping me understand the subject.