I seem to have an issue that I cant resolve. I have a jni dll that
calls SetWindowsHookE x with a callback to HookKeyboardPro c (basically
a real simple global keyboard hook). Now the dll almost works all the
jni hooks are fine and the program appears to run but the callback
(HookKeyboardPr oc) does not seem to get executed or possibly never
returns from execution. The code is as follows. None of the
variables being set in the code actually get set so im not sure what i
botched. The hook does complete successfully as it returns non-null
value for hkb. I would appreciate any help or suggestions on where to
get help.
Thanks
// syshook.cpp
/*
* SysHook - 7/17/05
* Jacob Gohlke
*
* JNI Interface for setting a Keyboard Hook and monitoring
* it Java-side
*
* (c) Copyright 2005 Jacob Gohlke
*
* Feel free to use and learn from this code, royalty-free!
* I only ask you acknkowlege what library you are using
* and who made it. Thanks, and happy hooking!
*/
#include <windows.h>
#include <winuser.h>
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include "org_dotnative_ globalkeylisten er_PollThread.h "
//#pragma data_seg(".HOOK DATA") //Shared data among all instances.
//#pragma data_seg("Share d")
static HHOOK hkb = NULL;
static HANDLE g_hModule = NULL;
static WPARAM g_wParam = 0;
static LPARAM g_lParam = 0;
static bool test = FALSE;
//extern "C" {
JNIEXPORT void NotifyJava(JNIE nv *env, jobject obj) {
jclass cls = env->GetObjectClass (obj);
jmethodID mid;
mid = env->GetMethodID(cl s, "Callback", "(ZIZZ)V");
if (mid == NULL) {
return;
}
if( (HIWORD( g_lParam ) & KF_UP) ) {
env->CallVoidMethod (obj, mid, (jboolean)FALSE , (jint)(g_wParam ),
(jboolean)(HIWO RD( g_lParam ) & KF_ALTDOWN), (jboolean)
(HIWORD( g_lParam ) & KF_EXTENDED));
}
else {
env->CallVoidMethod (obj, mid, (jboolean)TRUE, (jint)(g_wParam ),
(jboolean)(HIWO RD( g_lParam ) & KF_ALTDOWN), (jboolean)
(HIWORD( g_lParam ) & KF_EXTENDED));
}
}
//#pragma data_seg()
//#pragma comment(linker, "/SECTION:.HOOKDA TA,RWS")
LRESULT CALLBACK HookKeyboardPro c(INT nCode, WPARAM wParam, LPARAM
lParam) {
//printf("Callbac k\n");
test = TRUE;
if (nCode < 0) {
// do not process message
return CallNextHookEx( hkb, nCode, wParam, lParam);
}
g_wParam = wParam;
g_lParam = lParam;
return CallNextHookEx( hkb, nCode, wParam, lParam);
}
JNIEXPORT void JNICALL
Java_org_dotnat ive_globalkeyli stener_PollThre ad_checkKeyboar dChanges(JNIEnv
*env, jobject obj) {
if (test) {
printf("%i %i\n", g_wParam, g_lParam);
}
if(g_wParam != 0 && g_lParam != 0) {
NotifyJava(env, obj);
g_wParam = 0;
g_lParam = 0;
}
}
static void Init() {
hkb = SetWindowsHookE x(WH_KEYBOARD, (HOOKPROC)HookK eyboardProc,
(HINSTANCE)g_hM odule, 0);
printf("Call Init\n");
}
static void Cleanup() {
if (hkb != NULL) {
printf("Call Unhook\n");
UnhookWindowsHo okEx( hkb );
}
hkb = NULL;
printf("Call Clean\n");
}
//BOOL APIENTRY
//extern "C" BOOL WINAPI DllMain(HANDLE hModule, DWORD
ul_reason_for_c all, LPVOID lpReserved) {
extern "C" BOOL WINAPI DllMain(HANDLE hModule, DWORD
ul_reason_for_c all, LPVOID lpReserved) {
switch(ul_reaso n_for_call) {
case DLL_PROCESS_ATT ACH:
printf("Start\n ");
g_hModule = hModule;
Init();
return TRUE;
case DLL_PROCESS_DET ACH:
printf("Stop\n" );
Cleanup();
return TRUE;
}
return TRUE;
} 2 3894
Just out of curiosity, what made you think that [comp.lang.c++] would be
a good place to ask?
I think it might be a windows cpp issue.
KWhat4 wrote:
>Just out of curiosity, what made you think that [comp.lang.c++] would be a good place to ask?
I think it might be a windows cpp issue.
Try again. Try a newsgroup with either Microsoft or Java in its name. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brett Robichaud |
last post by:
I'm using an async delegate to spawn a thread and run some code. I also
specify an AsyncCallback to get notified when the thread completes. The
problem is that my callback is being called twice and I can't figure out
why. Here is a snippet of my code, the LoadImageThreadComplete() method is
being called twice even though LoadImage() is only ever called once. Any
ideas why?
delegate void LoadImageDelegate(string file);
private void...
|
by: Maxwell |
last post by:
Hello,
Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project
where I have a managed class reference in a unmanaged class...simple
enough. To keep things short I am for the most part attempting to do
what is this article by Nish:
http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw
I have to hook up a unmanaged callback to a managed method using IJW
NOT P\Invoke. So I am employing this "Thunk" or "Bridge" class...
|
by: bruno |
last post by:
I need some help on how write SetWindowsHookEx in vb.net 2005 to hook kb input.
this is the statement:
hHOOKKb = SetWindowsHookEx( _
WH_KEYBOARD, _
lpfn, _
hMod, _
dwThreadId)
And this is from MSDN Library:
lpfn Pointer to the hook procedure.
|
by: Udi |
last post by:
Hi all,
I'm having difficulties returning a buffer allocated on a callback
called from a native dll to .NET assembly.
(See pseudo code below in "Foo" func):
The managed assembly (the called back function) needs to allocate the
buffer and return it as an out param to the "C" dll.
When invoking the callback from the C code, passing a valid pointer
with sizeParam=0 cause the application to crash - I can't even enter
the callback scope....
|
by: Pradeep |
last post by:
Hi all,
Can any one explain me what is callback function....
I have written some code after reading some tutorials from internet...
But I am not sure is it a right way to write a call back function...
I have mentioned my doubts in code comments.
My code is...
void myfun_callback(void(*fp)(char*)) //is this function is a call
back?
{
| |
by: Tim Spens |
last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote:
I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via callback.setHandler1(callback1) this only seems to affect pythons ability to trigger an "event" in c. PyObject *Handler is always NULL even after I call Register_Handler(...). I thought there was some magic here that was assigning the pointer *Handler to my python...
|
by: jmDesktop |
last post by:
In a function that takes another function (function pointer) as a
argument, or the callback function, which is the one that "calls
back"? I'm having a hard time understanding the language.
Am I right that if function A is:
function A(*function pointer to B aka callback func, other arguments)
{
call (B); //calls
}
|
by: krungkrung |
last post by:
Hi everyone! Im new to vb.net. I'm currently recoding my vb6.0 codes to vb.net(for upgrading purposes), unfortunately some of the codes dont work/execute the way it executes in vb6.0, though I never get any error. That is, the program runs without error but the function being called dont execute. Can anybody help me figure out this matter??
***HERES WHAT SHOULD THE PROGRAM DO....
message box should always display at the center of the owner...
|
by: niksoftware |
last post by:
I'm making a kiosk style desktop replacement.
Im using setwindowshookex to run a callback system to trap the keys just trapping "windows" key atm.
if I step through just as the program goes the the keyboardcallback function declaration line it pauses for seconds before moving to the next line.
This directly precedes the new variable declaration of the callback variable
While running this leads to only 1 press of the "windows" keys...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |