frazap has asked for the wisdom of the Perl Monks concerning the following question:
lib/Kbh.pm
Makefile.plpackage Kbh; our $VERSION = '0.01'; require XSLoader; XSLoader::load('Kbh', $VERSION); sub process_key { print "process_key in perl\n"; } 1;
hook.huse ExtUtils::MakeMaker; WriteMakefile ( NAME => 'Kbh', VERSION => '0.01', OBJECT => 'hook.o Kbh.o', );
hook.cLRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam) +; void processKey(); void register_hook(); void unregister_hook(); void MsgLoop();
and Kbh.xs#include <windows.h> #include <WinAble.h> #include "stdio.h" #include "hook.h" HHOOK hook; LRESULT CALLBACK HookCallback( int nCode, WPARAM wParam, LPARAM lParam + ) { processKey(); return CallNextHookEx( hook, nCode, wParam, lParam ); } void processKey() { printf("processKey in C\n"); } void MsgLoop() { MSG message; while ( GetMessage( &message, NULL, 0, 0 ) ) { TranslateMessage(&message); DispatchMessage(&message); } } void register_hook() { HMODULE hMod = (HMODULE) GetModuleHandle(NULL); hook = SetWindowsHookEx( WH_KEYBOARD_LL, HookCallback, hMod, 0 ); } void unregister_hook() { UnhookWindowsHookEx(hook); }
When I run#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "hook.h" MODULE = Kbh PACKAGE = Kbh PROTOTYPES: DISABLE void MsgLoop() void register_hook() void unregister_hook() void processKey() INIT: int count; PPCODE: dSP; PUSHMARK(SP); count= call_pv("Kbh::process_key", G_DISCARD|G_NOARGS); if (count != 0) croak("Big trouble\n");
Perl Makefile.pl dmake
the things compile.
When I run runit.pl from the main directory(use ctrl+c to quit)
runit.plI see that the hook is installed, I get two messages from processKey when I hit a key, but I don't have msg "process_key from perl"use lib qw(./lib ./blib/arch/auto/Kbh); use Kbh; Kbh::register_hook(); Kbh::MsgLoop; Kbh::unregister_hook();
What am I missing ?
Thanks
François
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perlcall for dummies
by RMGir (Prior) on Sep 22, 2017 at 18:05 UTC | |
by frazap (Monk) on Sep 25, 2017 at 13:57 UTC | |
by RMGir (Prior) on Sep 25, 2017 at 17:44 UTC | |
Re: perlcall for dummies
by beech (Parson) on Sep 22, 2017 at 20:04 UTC | |
by frazap (Monk) on Sep 25, 2017 at 14:02 UTC |