MC百科社群
标题:
JNI的jdouble值错误救助
[打印本页]
作者:
000001912w
时间:
2023-2-11 23:28
标题:
JNI的jdouble值错误救助
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显示的值是一个随机的值
作者:
000001912w
时间:
2024-7-12 16:35
挖坟
现在知道了,不要用JNICALL JNI_OnLoad来注册,直接用javac -h生成就好了……
作者:
000001912w
时间:
2024-7-31 13:30
再挖坟(
真正原因是我没加JNIEXPORT修饰符
欢迎光临 MC百科社群 (https://bbs.mcmod.cn/)
MC百科
|最大的MineCraft中文模组百科