我是先写的DL序:
unit hkProc;
interfaceuses
Windows, Messages;
var
hNextHookProc: HHook;
procSaveExit: Pointer; function KeyboardHookHandler(iCode: integer; wParam: WPARAM; lParam: LPARAM):LRESULT;stdcall; export; function EnableHotKeyHook:BOOL;Export;
function DisableHotKeyHook:BOOL;export;
procedure HotKeyHookExit; far; implementation function keyboardHookHandler(iCode: integer; wParam: WPARAM; lParam: LPARAM):LRESULT;stdcall; export;
const
_keypressMaSK = $80000000;
begin
result:=0;
if icode<0 then
begin
    result:=CallNextHookEx(hNextHookProc,icode,wParam,lparam);          
exit;
end; if ((lparam and _KeyPressMask)=0)
            and(getkeystate(vk_control)<0)
            and(wParam=Ord('C'))
            then
begin
result:=1;
Winexec('c:\windows\system32\calc.exe',sw_normal);
end;
end; function Enablehotkeyhook: bool; export;
begin
result:=false;
if hnexthookproc<>0 then exit; hnexthookproc:=setwindowshookex(WH_KEYBOARD, KeyboardHookHandler, Hinstance, 0);
result:= hnextHookProc<>0;
end; function Disablehotkeyhook:BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNexthookProc:=0;
Messagebeep(0);
end;
result:=HnextHookproc=0;
end; procedure hotkeyhookexit;
begin
if hNexthookProc<>0 then DisableHotkeyHook;
exitproc:=procSaveExit;
end;
end.
然后编译成DLL文件,成功!
然后我写EXE程序调用这个DLL:代码如下:unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;implementation{$R *.dfm}function Enablehotkeyhook: bool; external 'hkkeytest.dll';function Disablehotkeyhook: bool; external 'hkkeytest.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
    if EnableHotkeyHook then
        showmessage('热键测试中...');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
    if Disablehotkeyhook then
    showmessage('完成测试!');
end;end.
可是运行时总是报错,提示信息是:
无法定位程序输入点 disablehotkeyhook于动态键接库hkkeytest.dll上.
我把disablehotkeyhook注释掉,运行时又说无法定位 Enablehotkeyhook
问题在哪儿啊?
高手指导一下.谢谢~~

解决方案 »

  1.   

    编译的是hkProc.dll??
    你调用的是hkkeytest.dll
      

  2.   

    不.编译成的文件就是hkkeytest.dll
    我只附上了PAS文件,还有DPR工程文件没有附上.工程文件里设置成编释成那个文件名的.
      

  3.   

    我把我的DLL文件上传到一个服务器上,只是源文件,所以不用担心是病毒,请高手帮我用DELPHI打开看看
    对不对~
    http://219.224.30.113/~lulu/question.rar
      

  4.   

    dll 调用声明区分大小写,把 Enablehotkeyhook 换成 EnableHotKeyHook,其他也一样。
      

  5.   

    dll调用区分大小写 声明时换成 EnableHotKeyHook ,DisableHotKeyHook