Ó¦¸Ã¿ÉÒԵģ¬·þÎñ³ÌÐòÒ²ÊÇÒ»ÖÖ¿ÉÖ´ÐÐÎļþ¶øÒÑ£¬°ïÄãÍÆÒ»ÏÂ

解决方案 »

  1.   

    我想要编写的是NT服务程序,我想这应该是NT/2000才有的,在控制面版服务项才能启动的,98下应该是没有NT服务程序这种说法的,所以应该不能在此基础上98下调试的
      

  2.   

    这说明你写的全局键盘钩子函数有问题啊。将你的DLL的Source贴出来才知道
    为什么。
      

  3.   

    全局键盘钩子函数源代码如下:
    library hook;{ Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }uses
      SysUtils,
      windows,
      messages,
      Classes;{$R *.res}
    var
    thehook:hhook;
    function winproc(iCode: Integer;wParam: WPARAM;lParam: LPARAM):integer;stdcall;
    begin
         Result := 0;                   
         if getkeystate(vk_space)<0 then                          
         begin
         messagebox(0,'KBHook is running!','KBhook',mb_ok);     
         result:=1;
         end
    end;
    procedure run();
    begin
        thehook:=setwindowshookex(WH_KEYBOARD,winproc,sysinit.HInstance,0);
    end;procedure stop();
    begin
         unhookwindowshookex(thehook);
    end;
    exports
           run,
           stop;end.
      

  4.   

    以上dll代码,我曾经用过form测试通过
      

  5.   

    刚才再看时发现上面说错了。还是Service程序的问题。你的Service程序一
    运行马上就结束了,所以不行。修改Service程序的ServiceExecute过程:
    procedure TService1.ServiceExecute(Sender: TService);
    begin
    run();
    ServiceThread.ProcessRequests(True); //行直到用户停止Service。
    stop();
    end;
    end.
      

  6.   

    函数winproc也需要修改一下:
    function winproc(iCode: Integer;wParam: WPARAM;lParam: LPARAM):integer;stdcall;
    begin
         if iCode < 0 then
         begin
            Result := CallNextHookEx(thehook, iCode, wParam, lParam);
            Exit;
         end;     Result := 0;
         if getkeystate(vk_space)<0 then                          
         begin
         messagebox(0,'KBHook is running!','KBhook',mb_ok
            + MB_SERVICE_NOTIFICATION);
         result := 1;
         end;
    end;
      

  7.   

    程序代码已经没有问题了,只是一个属性设定的问题。需要将Service的属性
    Interactive设成true。记住,需要先卸除原来的Service,再安装Service程
    序才可以。
      

  8.   

    我以前也试在Service中使用全局HOOK,没有起作用。