比如一个程序1.exe我注入到了1.exe,达到了键盘勾子,按F12后能创建我的DLL里的窗体并且呼出.有什么办法在不呼出dllform的时候能循环执行我的一段代码要求100毫秒执行一次
就好象建立正常程序里用timer一样.我知道DLL里也可以用timer,但是我的DLL注入到1.exe ,那时还没有创建窗体,所以不能使用 Timer控件.求助. 100毫秒执行一次 一个过程函数 
刚学DELPHI 语言表达不好请见谅

解决方案 »

  1.   

    没有窗口一样可以执行ttimer;
    建一个类:
    type Tmyclass=class
       public
          procedure mytimer(Sender: TObject);
    end;procedure Tmyclass.mytimer(Sender: TObject);
    begin
      ShowMessage('ok');  //这个仅是测试,可以写你的代码
    end;程序中:
    var
      t:ttimer;
      m: Tmyclass;
    begin
      m:= Tmyclass.Create;
      t:=ttimer.Create(nil);
      t.Interval:=2000;
      t.OnTimer:= m.mytimer;
      t.enabled=true;                 //2秒执行上面的代码

    注意,程序最后要
      m.free;
      t.free;
     
      

  2.   

    Sleep函数
      Sleep函数用来使程序的执行延时给定的时间值。Sleep的调用形式为Sleep(milliseconds),暂停当前的进程milliseconds毫秒。Sleep的实现方法其实也是调用Windows API的Sleep函数。例如:
    sleep(1000); //延迟1000毫秒
    Sleep会引起程序停滞,如果你延迟的时间较长的话,你的程序将不能够响应延时期间的发生的其他消息,所以程序看起来好像暂时死机。---------------------------------你尝试这个函数:
    procedure Delay(dwMilliseconds:DWORD);  //  Longint
    var
    iStart,iStop:DWORD;
    begin
        iStart :=   GetTickCount;
        repeat
        iStop  :=   GetTickCount;
        Application.ProcessMessages;
        until (iStop  -  iStart) >= dwMilliseconds;
    end;
      

  3.   

    我的DLL代码
    library Project2;uses
      windows,
      SysUtils,
      Classes;
    {$R *.res}Procedure tanmessage;StdCall;
    begin
    messagebox(0,'0','0',0) ;
    end;exports tanmessage;begin
    end.我刚把你的代码放进去出错,就是创建类的代码.
    请教
      

  4.   

    或者说有SetTimer的例子吗
    把SetTimer加到我的DLL里
      

  5.   

    注意头文件library testdll;{ 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,
      windows,ExtCtrls
      ;type Tmyclass=class 
      public
          procedure mytimer(Sender: TObject);
    end; procedure Tmyclass.mytimer(Sender: TObject); 
    begin 
      messagebox(0,'0','0',0) ;end; {$R *.res}
    Procedure tanmessage;StdCall;
    var 
      t:ttimer;
      m: Tmyclass; 
    begin 
      m:= Tmyclass.Create; 
      t:=ttimer.Create(nil); 
      t.Interval:=2000; 
      t.OnTimer:= m.mytimer; 
      t.enabled:=true;
    end;exports tanmessage;
    begin
    end.
      

  6.   

    用完后如何销毁timer 就是关闭谢谢 刚测试通过  
      

  7.   

    t.enabled:=false;
    这样无效呢..求教.
      

  8.   

    要销毁timer ,可以在DLL中设置全程的:新的DLL程序如下:library testdll;
    uses
      SysUtils,
      Classes,
      windows,ExtCtrls
      ;type Tmyclass=class 
      public
          procedure mytimer(Sender: TObject);
    end; procedure Tmyclass.mytimer(Sender: TObject); 
    begin 
      messagebox(0,'0','0',0) ;end; var 
      t:ttimer;
      m: Tmyclass;
    {$R *.res}
    Procedure tanmessage;StdCall;
    begin
      m:= Tmyclass.Create;
      t:=ttimer.Create(nil);
      t.Interval:=2000;
      t.OnTimer:= m.mytimer;
      t.enabled:=true;
    end;Procedure endtanmessage;StdCall;
    begin
      t.Enabled:=false;
      t.Free;
      m.Free;
    end;exports tanmessage,endtanmessage;
    begin
    end.
    在使用时,开始用    tanmessage;结束时用:endtanmessage;
      

  9.   

    真仔细,刚我也是全局变量 
    只是没加 t.Free;
           m.Free;
    谢谢了 结贴