From 9791a53061080e4b5a0c077134a7a16ad86c4a46 Mon Sep 17 00:00:00 2001
From: RocketDev <13736845354@163.com>
Date: Fri, 6 Aug 2021 19:30:56 +0800
Subject: [PATCH] solve the problem `issue #30` (#31)
---
pom.xml | 10 ++++++++++
src/main/cpp/JIntellitypeHandler.cpp | 19 ++++++++++---------
.../com_melloware_jintellitype_JIntellitype.h | 5 ++++-
.../melloware/jintellitype/JIntellitype.java | 2 +-
4 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/pom.xml b/pom.xml
index 301015d..0445ca3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -133,6 +133,16 @@
Strings for Register Hotkeys
+
+ Rocket
+ ma2014119@outlook.com
+ https://github.com/RocketMaDev
+
+
+
+ Make it usable above JDK 9
+
+
diff --git a/src/main/cpp/JIntellitypeHandler.cpp b/src/main/cpp/JIntellitypeHandler.cpp
index 666fc5d..ecf6c7f 100644
--- a/src/main/cpp/JIntellitypeHandler.cpp
+++ b/src/main/cpp/JIntellitypeHandler.cpp
@@ -24,6 +24,7 @@
#include "JIntellitypeHandler.h"
#include "JIntellitypeThread.h"
#include
+#include
UINT WM_SHELLHOOK = 0;
@@ -34,10 +35,10 @@ UINT WM_SHELLHOOK = 0;
JIntellitypeHandler *JIntellitypeHandler::extract( JNIEnv *env, jobject object )
{
// Get field ID
- jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( object ), "handler", "I" );
+ jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( object ), "handler", "J" );
// Get field
- JIntellitypeHandler *l_handler = (JIntellitypeHandler *) env->GetIntField( object, l_handlerId );
+ JIntellitypeHandler *l_handler = (JIntellitypeHandler *) env->GetLongField(object, l_handlerId);
return l_handler;
}
@@ -57,10 +58,10 @@ JIntellitypeHandler::JIntellitypeHandler( JNIEnv *env, jobject object )
m_fireIntellitype = env->GetMethodID( env->GetObjectClass( m_object ) , "onIntellitype", "(I)V" );
// Get field ID
- jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( m_object ) , "handler", "I" );
+ jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( m_object ) , "handler", "J" );
// Set field
- env->SetIntField( m_object, l_handlerId, (jint) this );
+ env->SetLongField( m_object, l_handlerId, (jlong) this );
}
/*
@@ -69,10 +70,10 @@ JIntellitypeHandler::JIntellitypeHandler( JNIEnv *env, jobject object )
JIntellitypeHandler::~JIntellitypeHandler()
{
// Get field ID
- jfieldID l_handlerId = g_JIntellitypeThread.m_env->GetFieldID( g_JIntellitypeThread.m_env->GetObjectClass( m_object ), "handler", "I" );
+ jfieldID l_handlerId = g_JIntellitypeThread.m_env->GetFieldID( g_JIntellitypeThread.m_env->GetObjectClass( m_object ), "handler", "J" );
// Set field
- g_JIntellitypeThread.m_env->SetIntField( m_object, l_handlerId, 0 );
+ g_JIntellitypeThread.m_env->SetLongField( m_object, l_handlerId, 0 );
// Release our reference
g_JIntellitypeThread.m_env->DeleteGlobalRef( m_object );
@@ -137,7 +138,7 @@ void JIntellitypeHandler::doInitialize()
return;
//Set pointer to this object inside the Window's USERDATA section
- SetWindowLong( m_window, GWL_USERDATA, (LONG) this );
+ SetWindowLongPtr( m_window, GWLP_USERDATA, (LONG_PTR) this );
// hide the window
ShowWindow(m_window, SW_HIDE);
@@ -255,7 +256,7 @@ LRESULT CALLBACK JIntellitypeHandler::WndProc( HWND hWnd, UINT uMessage, WPARAM
if (uMessage == WM_SHELLHOOK) {
if (wParam == HSHELL_APPCOMMAND) {
jint cmd = GET_APPCOMMAND_LPARAM(lParam);
- JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLong( hWnd, GWL_USERDATA );
+ JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLongPtr( hWnd, GWLP_USERDATA );
l_this->intellitype(cmd);
}
return TRUE;
@@ -264,7 +265,7 @@ LRESULT CALLBACK JIntellitypeHandler::WndProc( HWND hWnd, UINT uMessage, WPARAM
// check for registered hotkey messages and send them to HotKeyListeners
switch( uMessage ) {
case WM_HOTKEY: {
- JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLong( hWnd, GWL_USERDATA );
+ JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLongPtr( hWnd, GWLP_USERDATA );
l_this->fireHotKey(wParam);
return TRUE;
break;
diff --git a/src/main/cpp/com_melloware_jintellitype_JIntellitype.h b/src/main/cpp/com_melloware_jintellitype_JIntellitype.h
index ddbfe34..e2bf6d0 100644
--- a/src/main/cpp/com_melloware_jintellitype_JIntellitype.h
+++ b/src/main/cpp/com_melloware_jintellitype_JIntellitype.h
@@ -31,6 +31,9 @@ JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_regHotKey
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_terminate
(JNIEnv *, jobject);
+JNIEXPORT jboolean JNICALL Java_com_melloware_jintellitype_JIntellitype_isRunning
+ (JNIEnv* env, jclass, jstring wndName);
+
/*
* Class: com_melloware_jintellitype_JIntellitype
* Method: unregHotKey
@@ -45,7 +48,7 @@ JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_unregHotKey
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_com_melloware_jintellitype_JIntellitype_isRunning
- (JNIEnv *, jobject, jstring);
+ (JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
diff --git a/src/main/java/com/melloware/jintellitype/JIntellitype.java b/src/main/java/com/melloware/jintellitype/JIntellitype.java
index 77d7ab7..266a85f 100644
--- a/src/main/java/com/melloware/jintellitype/JIntellitype.java
+++ b/src/main/java/com/melloware/jintellitype/JIntellitype.java
@@ -97,7 +97,7 @@ public final class JIntellitype implements JIntellitypeConstants {
/**
* Handler is used by JNI code to keep different JVM instances separate
*/
- private final int handler = 0;
+ private final long handler = 0;
/**
* Map containing key->keycode mapping