将此dll注入java程序时,程序立即停止响应。当我打开调试器时,它说我试图用env-> FindClass找到的类等于0x000000000000(NULL)。无法弄清楚为什么我确定给出的路径是正确的......
以下是我的测试项目的MainThread代码:
#include <Windows.h>
#include <jni.h>
DWORD WINAPI Main_Thread(LPVOID lpParam)
{
HMODULE m_hDllInstance = LoadLibraryA("jvm.dll");
JavaVM *jvm;
JNIEnv *env;
typedef jint(JNICALL * GetCreatedJavaVMs)(JavaVM**, jsize, jsize*);
GetCreatedJavaVMs jni_GetCreatedJavaVMs = (GetCreatedJavaVMs)GetProcAddress(m_hDllInstance, "JNI_GetCreatedJavaVMs");
jint size = 1;
jint vmCount;
jint ret = jni_GetCreatedJavaVMs(&jvm, size, &vmCount);
jint rc = jvm->AttachCurrentThread((void **)& env, NULL);
//NULL?
jclass PlayerControllerMP = env->FindClass("net/minecraft/client/multiplayer/PlayerControllerMP"); //NULL?
jmethodID constructor = env->GetStaticMethodID(PlayerControllerMP, "<init>", "(Minecraft, NetHandlerPlayClient)PlayerControllerMP");
jobject pcmpObj = env->NewObject(PlayerControllerMP, constructor);
jmethodID getReach = env->GetMethodID(PlayerControllerMP, "getBlockReachDistance", "()F");
while (!GetAsyncKeyState(VK_END))
{
env->CallFloatMethod(pcmpObj, getReach);
}
jvm->DetachCurrentThread();
return S_OK;
}
感谢您的帮助,抱歉,如果代码看起来有点搞笑,则无法粘贴它。