invokemethodlibrary.cpp
来自「< Professional Java,JDK 5 Edition>」· C++ 代码 · 共 50 行
CPP
50 行
// InvokeMethodLibrary.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "..\InvokeMethodExample.h"
JNIEXPORT void JNICALL Java_InvokeMethodExample_execMethods
(JNIEnv *env, jobject obj)
{
jclass childClass, parentClass;
jmethodID parent_methodID, child_methodID;
childClass = env->GetObjectClass(obj);
parentClass = env->FindClass("InvokeMethodParentClass");
if(childClass == NULL || parentClass == NULL) {
printf("Couldn't obtain handle to parent or child class");
return;
}
parent_methodID = env->GetMethodID(parentClass, "printMessage", "()V");
child_methodID = env->GetMethodID(childClass, "printMessage", "()V");
if(parent_methodID == NULL || child_methodID == NULL) {
printf("Couldn't obtain handle to parent or child method");
return;
}
// These two calls invoke the method on the child class
env->CallVoidMethod(obj, parent_methodID);
env->CallVoidMethod(obj, child_methodID);
// These two calls invoke the method on the parent class
env->CallNonvirtualVoidMethod(obj, childClass, parent_methodID);
env->CallNonvirtualVoidMethod(obj, parentClass, parent_methodID);
// These two calls invoke the method on the child class
env->CallNonvirtualVoidMethod(obj, childClass, child_methodID);
env->CallNonvirtualVoidMethod(obj, parentClass, child_methodID);
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?