Click here to Skip to main content
15,921,793 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalvisual c++ 7 Pin
11-Jun-01 23:52
suss11-Jun-01 23:52 
GeneralRe: visual c++ 7 Pin
Michael P Butler12-Jun-01 0:04
Michael P Butler12-Jun-01 0:04 
GeneralRe: visual c++ 7 Pin
Derek Lakin12-Jun-01 0:05
Derek Lakin12-Jun-01 0:05 
GeneralTrackMouseEvent question Pin
11-Jun-01 21:44
suss11-Jun-01 21:44 
General2 Pin
11-Jun-01 21:44
suss11-Jun-01 21:44 
QuestionSetting wide message system hook? Pin
11-Jun-01 21:13
suss11-Jun-01 21:13 
AnswerRe: Setting wide message system hook? Pin
Igor Sukhov12-Jun-01 3:14
Igor Sukhov12-Jun-01 3:14 
AnswerRe: Setting wide message system hook? Pin
Jason Teagle12-Jun-01 4:56
Jason Teagle12-Jun-01 4:56 
I had this exact same problem. Here's the reason:

Whenever an app or DLL does something which triggers your hook, the system loads and maps a copy of your hook DLL into that process. Thus, the system has X copies of your DLL. Each DLL has SEPARATE data. Thus, the original DLL you load to run the hook is not aware of a variable being set in another instance of the DLL.

What you need to do is create a shared segment in your DLL, as follows (in the CPP file, not in any routine but out in the open):

#pragma data_seg(".shared")
HHOOK g_hHook = NULL ;
HWND g_hWndSelected = NULL ;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.shared,RWS")

Any variable that gets set or used by the hook (except local variables, of course, since they are only temporary anyway) should be in this section so that ALL of the loaded DLL instances see that variable get the new value. For example, the hook handle above is used when calling CallNextHook(), since whichever instance of the DLL gets activated, it needs the handle to pass on. Similarly, if the activation code makes a note of the handle of a window being clicked by the mouse, then that window handle must be in the shared section (as the example above shows).

By doing the above, when your app that installed the hook goes to its original instance of the DLL and asks for the handle of the clicked window, your DLL can see the data even if another instance set it.

I hope that clears up the problem, it did for me Smile | :)
GeneralDon't include header files. Pin
hahyojin11-Jun-01 19:17
hahyojin11-Jun-01 19:17 
Generalplease translate ;) Re: Don't include header files. Pin
Igor Sukhov11-Jun-01 23:02
Igor Sukhov11-Jun-01 23:02 
Generalwe all <i><b>love</b></i> an inheritance question! Pin
Nick Blumhardt11-Jun-01 17:37
Nick Blumhardt11-Jun-01 17:37 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Gerald Schwab11-Jun-01 17:58
Gerald Schwab11-Jun-01 17:58 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Nick Blumhardt11-Jun-01 19:06
Nick Blumhardt11-Jun-01 19:06 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Ben Burnett11-Jun-01 19:21
Ben Burnett11-Jun-01 19:21 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Gert Boddaert11-Jun-01 21:38
Gert Boddaert11-Jun-01 21:38 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Nick Blumhardt12-Jun-01 13:21
Nick Blumhardt12-Jun-01 13:21 
GeneralRe: we all <i><b>love</b></i> an inheritance question! Pin
Gerald Schwab12-Jun-01 15:02
Gerald Schwab12-Jun-01 15:02 
Generalusing unicode symbols in embedded VC++ Pin
bo11-Jun-01 17:01
bo11-Jun-01 17:01 
GeneralProgram crashes when I try to assign values to a CListBox in a dialog window created from my main dialog window Pin
11-Jun-01 16:06
suss11-Jun-01 16:06 
GeneralRe: Program crashes when I try to assign values to a CListBox in a dialog window created from my main dialog window Pin
11-Jun-01 18:14
suss11-Jun-01 18:14 
GeneralNope Pin
11-Jun-01 23:44
suss11-Jun-01 23:44 
GeneralRe: Program crashes when I try to assign values to a CListBox in a dialog window created from my main dialog window Pin
Ben Burnett11-Jun-01 19:27
Ben Burnett11-Jun-01 19:27 
GeneralCrashes no matter where Pin
11-Jun-01 23:47
suss11-Jun-01 23:47 
GeneralRe: Crashes no matter where Pin
Michael P Butler12-Jun-01 0:08
Michael P Butler12-Jun-01 0:08 
GeneralRe: Crashes no matter where Pin
12-Jun-01 0:26
suss12-Jun-01 0:26 

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.