-
March 4th, 2001, 03:07 AM
#1
Accessing global variables inside a hook procedure in a simple win32 dll.
HI,
I have a system wide WH_CBT hook installed in a simple win32 dll. The way it works is, I have some global variables like so:
UINT uArr[10];
int iCount = -1;
WinMain(.....)
{
//do stuff
.....
}
Now, in the hook procedure, I am doing things like this:
LRESULT CALLBACK MyCbtProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(some condition)
uArr[++iCount] = some numeric value;
The problem I have is: EVERY TIME, the hook procdure gets called, the value of iCount is -1. I want the values of these global variables to 'persist' because I need to reset some things when the hook gets un-installed. Am I missing some thing obvious?
Any help appreciated.
Nas.
What matters in a fight, is not the size of the dog in the fight. It is the size of the fight...in the dog!
-
March 4th, 2001, 01:52 PM
#2
Re: Accessing global variables inside a hook procedure in a simple win32 dll.
DLL containing system wide hook is loaded into different processes
in the system. By default each copy of the DLL gets private copy
of the data. If you want some data to be shared across all instances
of the DLL, put them into a shared section.
Example:
#pragma comment(linker, "/section:.shared,rws")
#pragma data_seg(".shared")
HHOOK gs_hHook = NULL;
UINT gs_uArr[10] = { 0 };
int gs_iCount = -1;
#pragma data_seg()
Note, all variables in the shared segment must be explicitly initialized,
otherwise the compiler will put them into the BSS segment.
-
September 2nd, 2014, 02:52 PM
#3
Re: Accessing global variables inside a hook procedure in a simple win32 dll.
At the risk of creating an internet feedback loop, I had this same issue more less and got help and solved it here:
http://www.codeproject.com/Questions...10#cmt2_813987
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|