dll not working II ....

in main program i have
Procedure RunStopHook(State : boolean) stdcall;
external 'sdf.dll' index 1;
in form create  i   have RunStopHook(true); which start the hook

in sdf.dll I have :
function SetHook(Hook : Boolean) : Boolean; export; stdcall;
begin
  Result := false;
  if Hook
  then
    begin
      if SysHook = 0
      then
        SysHook := SetWindowsHookEx(WH_SHELL{WH_CBT,WH_CALLWNDPROC}, @SysMsgProc, HInstance, 0);
      Result := (SysHook <> 0);
    end
  else
    begin
      if SysHook <> 0
      then
        begin
          UnhookWindowsHookEx(SysHook);
          SysHook := 0;
          Result := true;
        end;
    end;
end;

----------------------------------------
when programs runs about 10 minits sudednly it  stops  hooking. when i press button start hook wich have StartStopHook(true); then nothing happens, but if I press STOP hook button and after START  hook button (stop hook calls StartStopHook(false)  and Start hook button calls StartStopHook(true)) then hook resume  his work. why it stops  suddenly ??? and after  stoping and starting it, it starts again
andrezzzAsked:
Who is Participating?
 
robert_marquardtCommented:
This looks like the common problem of global hooks in a DLL.
The SysHook vaiable has to reside in a shared segment of the DLL.
Delphi cannot create such a shared segment.
See Borland Code Central entry 15387 for a tool to patch a shared segment into ehe DLL.

The problem stems from the fact that a hook DLL gets loaded into *all* running programs. That means each program gets a *copy* of the DLL.
Only the DLL copy where your SetHook is called has an initialized data segment (global variables) where SysHook is assigned.
0
 
andrezzzAuthor Commented:
i can't open http://cc.borland.com/ccweb.exe/listing?id=15387
where i can  find this tool  ???? the  borland page show some error
0
 
_Katka_Commented:
Hi, this page opens well for me:

try directly: http://cc.borland.com/ccweb.exe/download?id=15387

regards,
Kate

0
 
robert_marquardtCommented:
If not then go to Borland Community and search for shared segment. The tool is from Petr Vones so you may add his name to the search also.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.