Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Hook" type program? 1

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
Have a thought provoking question. Let's say that I had a program that was using the registry and another program that read those values the first program was putting into the registry. Is there some way I can use a "hook" of sorts that I can setup so that I will know when something has changed in the registry? I don't want to use a timer..that's what I'm using now. Just some sort of way I can fire off a function when a certain value in the registry is changed. Thanks in advance!

Niky Williams
Lead Engineer
NTS Marketing, Inc.
 
I think a win32 hook would be overkill for this situation. Instead why not have the registry writting program communicate with the registry reading program after a key has been modified. After your data has been stored in the registry by your program, have it "send a message" to the program that will attempt to read it. This message hand off can be accomplished via a SendMessage() call. Windows provides a default program specific message called WM_USER. You can catch this message and respond to it.
After your window has written info. into the registry, you could do somthing like this ->

SendMessage( hReadRegistry,WM_USER,NULL,NULL );

Where hReadRegistry is the handle to your window that will attemp to extract information from the registry. Then just catch and respond to this message. Mike L.G.
mlg400@blazemail.com
 
Oh, now THAT is a cool idea. I never thought of doing that. I didn't even think it was possible to send messages between 2 seperate programs. Thanks for the awesome idea! Just out of curiosity, if I wanted to look into hooks, where would be a good place to start? I mean, just give me a few function names that are used and I can research them from there. Thanks again!

Niky Williams
Lead Engineer
NTS Marketing, Inc.
 
The raw win32 api contains some nice registry handling functions. To get you started, you might was to research the following api calls ->

LONG RegOpenKeyEx( HKEY hKey,LPCSTR pszSubKey,
DWORD NotUsed,REGSAM Access,
PHKEY Result );

LONG RegSetValueEx( HKEY hKey,LPCSTR lpszName,
DWORD NotUsed,DWORD DataType,
CONST LPBYTE lpValue,DWORD size );

LONG RegQueryValueEx( HKEY hKey,LPSTR lpszName,
LPDWORD NotUsed,LPDWORD DataType,
LPBYTE Value,LPDWORD SizeOfData ); Mike L.G.
mlg400@blazemail.com
 
Here are some functions that install hooks etc...made possible via the win32 api ->

HHOOK SetWindowsHookEx( int type,HOOKPROC HookFunc,
HINSTANCE hInst,DWORD ThreadID );

BOOL UnhookWindowsHookEx( HHOOK HookFunc );

LRESULT CallNextHookEx( HHOOK CurHook,int code,
WPARAM wParam,LPARAM lParam );

Mike L.G.
mlg400@blazemail.com
 
I am currently using those API calls. The program I'm doing right now is pure Win32 API. Currently I just have a timer checking the registry every once and a while so the program knows what to do...least it will be like that until I can implement the messaging system you proposed. Thanks again for the info!

Niky Williams
Lead Engineer
NTS Marketing, Inc.
 
Okay, I can run from there with those functions that install hooks. Probably won't be doing too much with them now that I know I can use messages. Thanks again for your help!

Niky Williams
Lead Engineer
NTS Marketing, Inc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top