Click here to Skip to main content
14,333,745 members
   

Delphi

 
QuestionThe Community? Pin
DonaldDuvall13-Dec-10 7:38
memberDonaldDuvall13-Dec-10 7:38 
AnswerRe: The Community? Pin
RaviRanjanKr13-Dec-10 19:04
professionalRaviRanjanKr13-Dec-10 19:04 
AnswerRe: The Community? Pin
nortee13-Dec-10 21:19
membernortee13-Dec-10 21:19 
AnswerRe: The Community? Pin
Blue_Boy17-Dec-10 3:24
memberBlue_Boy17-Dec-10 3:24 
AnswerRe: The Community? Pin
Dr.Walt Fair, PE23-Dec-10 19:38
professionalDr.Walt Fair, PE23-Dec-10 19:38 
AnswerRe: The Community? Pin
#realJSOP31-Dec-10 4:27
mve#realJSOP31-Dec-10 4:27 
GeneralRe: The Community? Pin
nortee17-Jan-11 23:49
membernortee17-Jan-11 23:49 
QuestionAbout Delphi KeyBoard Hook question,I need your help ! Pin
true_jeamy12-Jun-10 20:36
membertrue_jeamy12-Jun-10 20:36 
I program on Delphi 7 .

First I Create a DLL

Code :
library HookDLL;

{ 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,Dialogs,windows;

{$R *.res}

var
  hookHandle:HHOOK;
  hookCode:string;

  function KeyBoardHook(code:Integer;
                        wparaw:Cardinal;
                        lparaw:Cardinal):Cardinal;stdcall;
  begin
     if code >0 then
     begin
      // hookCode := hookCode + IntToStr(code);
       ShowMessage(IntToStr(code));
       CallNextHookEx(hookHandle,code,wparaw,lparaw);
     end;
  end;

  function StartHook(instance:Cardinal;SysType:Integer):Boolean;stdcall;
  begin
       hookHandle := SetWindowsHookEx(WH_KEYBOARD,@KeyBoardHook,instance,SysType);
       if hookHandle <> 0 then
       begin
         ShowMessage('install Success!');
         Result := True;
       end
       else
       begin
         ShowMessage('install Error!'); 
         Result := False;
       end;
  end;



  function UnSetHook:Boolean;stdcall;
  begin
      Result := UnhookWindowsHookEx(hookHandle);
  end;

  function GetPass:string;stdcall;
  begin
    Result := hookCode;
  end;

  exports
      StartHook,GetPass,UnSetHook;

  begin

  end.


and use code

unit SetHook;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    btn3: TButton;
    tmr1: TTimer;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
    procedure tmr1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
  Form1: TForm1;

  function UnSetHook:Boolean; external 'HookDLL.dll';
  function GetPass:string; external 'HookDLL.dll';
  function StartHook(instance:Cardinal;proId:Integer):Boolean; external 'HookDLL.dll';
  
implementation

{$R *.dfm}

var
    pid:Cardinal;
procedure TForm1.btn1Click(Sender: TObject);
begin
    Application.MessageBox(PChar(GetPass), 'information', MB_OK +
      MB_ICONINFORMATION);
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
  UnSetHook;
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
if StartHook(HInstance,pid) then
  begin
    Application.MessageBox('Hook Install Success!', 'information', MB_OK +
      MB_ICONINFORMATION);

  end;
end;

procedure TForm1.tmr1Timer(Sender: TObject);
var
  hwnd:THandle;
begin
  hwnd := FindWindow(nil,'hookpro');
  if hwnd = 0 then
  begin
    Exit;
  end;
  pid := GetWindowThreadProcessId(hwnd,nil);
  if pid = 0 then
  begin
    Exit;
  end;
end;

end.


when i set the windows hook ,the program throw a exception!
and show 'install Error!'


so I need your help!

E-mail : 1102043058@qq.com
AnswerRe: About Delphi KeyBoard Hook question,I need your help ! Pin
dan_fish23-Aug-10 2:52
memberdan_fish23-Aug-10 2:52 
AnswerRe: About Delphi KeyBoard Hook question,I need your help ! Pin
Dr.Walt Fair, PE12-Dec-10 12:36
professionalDr.Walt Fair, PE12-Dec-10 12:36 
AnswerRe: About Delphi KeyBoard Hook question,I need your help ! Pin
nortee12-Dec-10 21:44
membernortee12-Dec-10 21:44 
AnswerRe: About Delphi KeyBoard Hook question,I need your help ! Pin
GAMerritt18-Jan-11 4:52
memberGAMerritt18-Jan-11 4:52 
QuestionExposing C# COM server Events to Delphi client Pin
shilan_hk11-Jun-10 22:08
membershilan_hk11-Jun-10 22:08 
AnswerRe: Exposing C# COM server Events to Delphi client Pin
dan_fish23-Aug-10 2:46
memberdan_fish23-Aug-10 2:46 
QuestionDelphi DLL function calling from VB.net and C#.net paramters compatibility Pin
vijay.victory12-Apr-10 0:39
membervijay.victory12-Apr-10 0:39 
AnswerRe: Delphi DLL function calling from VB.net and C#.net paramters compatibility Pin
mobius11100112-Apr-10 2:37
membermobius11100112-Apr-10 2:37 
QuestionUnicode parameter in Select Query Pin
vijay.victory31-Mar-10 19:28
membervijay.victory31-Mar-10 19:28 
AnswerRe: Unicode parameter in Select Query Pin
nortee13-Dec-10 21:34
membernortee13-Dec-10 21:34 
QuestionFreeDOS Scandisk - Compilation Errors for Pascal code Pin
Low_Level14-Mar-10 5:50
memberLow_Level14-Mar-10 5:50 
AnswerRe: FreeDOS Scandisk - Compilation Errors for Pascal code Pin
Richard MacCutchan14-Mar-10 7:13
protectorRichard MacCutchan14-Mar-10 7:13 
GeneralRe: FreeDOS Scandisk - Compilation Errors for Pascal code Pin
Low_Level14-Mar-10 7:31
memberLow_Level14-Mar-10 7:31 
GeneralRe: FreeDOS Scandisk - Compilation Errors for Pascal code Pin
Low_Level14-Mar-10 7:33
memberLow_Level14-Mar-10 7:33 
QuestionSQL Server 2005 Connection Strings.....Some Important Queries Pin
vijay.victory5-Mar-10 21:28
membervijay.victory5-Mar-10 21:28 
AnswerRe: SQL Server 2005 Connection Strings.....Some Important Queries Pin
Eddy Vluggen6-Mar-10 1:11
mveEddy Vluggen6-Mar-10 1:11 
QuestionSlow Performance of SQL Server 2005... Pin
vijay.victory3-Mar-10 2:51
membervijay.victory3-Mar-10 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.