一个困扰我几天的问题

一个困扰我几天的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061128134457154.html
郁闷啊!下面这段代码是dll中的键盘钩子的回调函数,想在这个回调函数中打开  
  dll中的窗体!但是现在连编译都过不了。  
   
   
   
  这是drhook   工程文件:  
   
  library   drHook;  
   
  {   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,  
      Classes,  
      Forms,  
      Unit2   in   'Unit2.pas',  
      Unit1   in   'Unit1.pas'   {Form1};  
   
   
  {$R   *.res}  
   
  exports  
      CreateKeyboardHook,  
      DestroyKeyboardHook;  
  begin  
      hNextHookProc   :=   0;  
      procSaveExit   :=   ExitProc;  
      ExitProc   :=   @KeyboardHookExit;  
  end.  
   
  这是dll中的键盘钩子:  
   
   
  unit   Unit2;  
   
  interface  
   
  uses  
      Windows,   SysUtils;  
  var  
      hNextHookProc:   HHook;  
      procSaveExit:   Pointer;  
   
  function   KeyboardHookProc(code:   Integer;   wparam:   WPARAM;  
      lparam:   LPARAM):   LRESULT   stdcall;   export;  
  function   CreateKeyboardHook:   BOOL;   stdcall;   export;  
  function   DestroyKeyboardHook:   BOOL;   stdcall;   export;  
  procedure   KeyboardHookExit;  
   
  implementation  
   
  var  
      GameSwitch:   Word;         //程序热键  
   
  function   KeyboardHookProc(code:   Integer;   wparam:   WPARAM;  
      lparam:   LPARAM):   LRESULT;  
  const  
      _KeyProcessMask   =   $80000000;  
  begin  
      Result   :=   0;  
      if   code   <   0   then  
      begin  
          Result   :=   Windows.CallNextHookEx(hNextHookProc,   code,   wparam,   lparam);  
          Exit;  
      end;  
      if   ((lparam   and   _KeyProcessMask)   =   0)   and   (wparam   =   GameSwitch)   then  
      begin  
          Application.Handle   :=   GetForegroundWindow;     //返回当前窗口句柄  
          Result   :=   1;  
      end;  
  end;  
   
  function   CreateKeyboardHook:   BOOL;  
  begin  
      Result   :=   false;  
      if   hNextHookProc   <>   0   then  
          exit;  
      hNextHookProc   :=   Windows.SetWindowsHookEx(WH_KEYBOARD,   @KeyboardHookProc,  
          hInstance,   0);  
      Result   :=   hNextHookProc   <>   0;  
  end;  
   
  function   DestroyKeyboardHook:   BOOL;  
  begin  
      if   hNextHookProc   <>   0   then  
      begin  
          Windows.UnhookWindowsHookEx(hNextHookProc);  
          hNextHookProc   :=   0;  
      end;  
      Result   :=   hNextHookProc   =   0;  
  end;  
   
  procedure   KeyboardHookExit;  
  begin  
      if   hNextHookProc   <>   0   then  
          DestroyKeyboardHook;  
      ExitProc   :=   procSaveExit;  
  end;  
   
  Initialization  
      GameSwitch   :=   VK_HOME;  
   
  end.  
   
  这是那个窗体文件,啥都没有,就一个空窗体,我就想让他显示。。。  
  困扰好久了。。。。比较菜  
   
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  type  
      TForm1   =   class(TForm)  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
   
   
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
   
  {$R   *.dfm}  
   
   
  end.  
   
   
  希望那位大哥能指点指点,小弟先谢谢了。。。。  
 

uses  
      Windows,   SysUtils,   Forms;   //   add   Forms  
   
   
  Application声明在Forms单元中,难道你没有看帮助?

zswang(伴水清清)   谢谢你!  
   
  我知道这点,但是加上forms后   那个窗体就调不出来了。。。  
   
  好郁闷。。

转载于:https://www.cnblogs.com/delphi2007/archive/2008/11/27/1342590.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值