I've created a Windows registry entry in HKEY_CLASSES_ROOT* with the value: "C:\test.exe" "%1" to create a new right-click context menu entry that passes the filepath of the clicked file to the registered test.exe. Inside the test.exe a dll-file is loaded that should inject into an already running jvm to call a method and pass the filepath. The problem is that the .dll does not find a JVM instance although it is running in a while-loop (prototype). Could you please help me to solve that problem? How do I have to access the JVM? Thanks
.java:
public class Main
{
public static void main(String[] args)
{
while(true)
{
}
}
public static void readAndOutputFilePath(String result)
{
System.out.println("Java result: "+result);
try
{
System.in.read();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
.dll:
HMODULE m_hDllInstance = LoadLibrary("jvm.dll");
if( m_hDllInstance == 0)
{
printf("The jvm.dll could not be found");
getchar();
}
else
printf("jvm.dll found");
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);
cout << endl << "GetCreated: " << vmCount << endl;
getchar();
jint rc = jvm->AttachCurrentThread((void **) & env, NULL);
jclass cls = env->FindClass("Main");
jmethodID mid = env->GetStaticMethodID(cls, "readAndOutputFilePath", "(Ljava/lang/String;)V");
jstring resultString = env->NewStringUTF(path);
env->CallStaticVoidMethod(cls, mid, resultString);
...