我懂java,但对c++和VisualStudio完全陌生。我试图从两个源文件(cpp和h)构建一个dll文件。为了在java应用程序(jni/jna)中使用本机函数,我需要这个。这是一种全局键挂钩,应该重新Map键盘按钮,我希望。
但当我粘贴源代码时,有些地方用红色突出显示,上面写着:
cpp文件
“无法打开源文件w32api.h”。我用vs和俄语,所以我翻译了它。
“error type”jniexport此声明不包含存储类或类型说明符
h文件
“error type”jniexport此声明不包含存储类或类型说明符
下面是源代码:
remapkeys.h公司
/* DO NOT EDIT THIS FILE - it is machine generated */
# include <jni.h>
/* Header for class com_cooltrickshome_RemapKeys */
# ifndef _Included_com_cooltrickshome_RemapKeys
# define _Included_com_cooltrickshome_RemapKeys
# ifdef __cplusplus
extern "C" {
# endif
/*
* Class: com_cooltrickshome_RemapKeys
* Method: remapPassedKeys
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_com_cooltrickshome_RemapKeys_remapPassedKeys
(JNIEnv*, jobject, jint, jint);
# ifdef __cplusplus
}
# endif
# endif
remapkeys.cpp文件
# include <stdio.h>
# include <windows.h>
# include <w32api.h>
# include "RemapKeys.h"
static HHOOK handleKeyboardHook = NULL;
HINSTANCE hInst = NULL;
DWORD oldKey = NULL;
DWORD newKey = NULL;
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
if (p->vkCode == oldKey)
{
switch (wParam) {
case WM_KEYDOWN: {
keybd_event(newKey, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0);
break;
}
case WM_KEYUP: {
keybd_event(newKey, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
break;
}
default:
wParam = WM_SYSKEYDOWN;
break;
}
return 1;
}
}
return CallNextHookEx(handleKeyboardHook, nCode, wParam, lParam);
}
JNIEXPORT void JNICALL Java_com_cooltrickshome_RemapKeys_remapPassedKeys
(JNIEnv*, jobject, jint oldValue, jint newValue) {
/* printf("Your message here\n");
fflush(stdout);*/
oldKey = oldValue;
newKey = newValue;
hInst = GetModuleHandle(NULL);
handleKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInst, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
我做错了什么?有人能帮我吗?先谢谢你。
暂无答案!
目前还没有任何答案,快来回答吧!