dll部分源码:
void setSpeed(JNIEnv_* env, double speed) {
MessageBox(NULL, to_wstring(speed).c_str(), L"speed", MB_OK);
speed4f = speed;
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* jvm, void* res) {
JNIEnv_* env;
if (JNI_OK != jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_8))
{
MessageBox(NULL, L"JNI_OnLoad couldn't get JNIEnv_", L"JNI ERR", MB_OK);
return JNI_ERR;
}
HMODULE lwjgl_opengl = GetModuleHandle(L"lwjgl_opengl.dll");
if (lwjgl_opengl == 0)
{
MessageBox(NULL, L"JNI_OnLoad couldn't find lwjgl_opengl.dll", L"DLL ERR", MB_OK);
return JNI_ERR;
}
color4f=(typeGLcolor4f)GetProcAddress(lwjgl_opengl, "Java_org_lwjgl_opengl_GL11_glColor4f");
jclass gl11 = env->FindClass("org/lwjgl/opengl/GL11");
jclass mod = env->FindClass("net/mcreator/colourful/ColourfulMod");
JNINativeMethod colourfulGL[] = { { "glColor4f","(FFFF)V",reinterpret_cast<void*>(myColourfulGLcolor4f)} };
JNINativeMethod nsetSpeed[] = { { "setSpeed","(D)V",reinterpret_cast<void*>(setSpeed)} };
JNINativeMethod nsetEnabled[] = { { "setEnabled","(Z)V",reinterpret_cast<void*>(setEnabled)} };
env->RegisterNatives(gl11, colourfulGL, 1);
env->RegisterNatives(mod, nsetSpeed, 1);
env->RegisterNatives(mod, nsetEnabled, 1);
return env->GetVersion();
}
ColourfulMod.class里:
setSpeed(ColourModCfg.Speed.get());
public static native void setSpeed(double speed);
MessageBox显示的值是一个随机的值 |
|