[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

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
0
andrezzz
Asked:
andrezzz
  • 2
2 Solutions
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now