2

Java アプリケーションを実行するための .exe を作成しようとしています。次のコードがあります。

Labyrinth.c

#include <windows.h>
#include <stdio.h>
#include <jni.h>

#define MAIN_CLASS "game/main/Game"

__declspec(dllexport) __stdcall int run(){
    JNIEnv*         env;
    JavaVM*         jvm;
    JavaVMInitArgs  vmargs;
    JavaVMOption    options[1];
    jint            rc;
    jclass          class;
    jmethodID       mainID;

    vmargs.version = 0x00010002;
    options[0].optionString = "-Djava.class.path=.";
    vmargs.options = options;
    vmargs.nOptions = 1;
    rc = JNI_CreateJavaVM(&jvm, (void**) &env, &vmargs);
    if(rc < 0){
        printf("Failed creating JVM");
        return 1;
    }
    class = (*env)->FindClass(env, MAIN_CLASS);
    if(class == 0){
        printf("Failed finding the main class");
        return 1;
    }
    mainID = (*env)->GetStaticMethodID(env, class, "main", "([Ljava/lang/String;)V");
    if(mainID == 0){
        printf("Failed finding the main method");
        return 1;
    }
    (*env)->CallStaticVoidMethod(env, class, mainID, 0);
    (*jvm)->DestroyJavaVM(jvm);
    return 0;
}

その後、OpenLabyrinth.dll にコンパイルされます。

そして、dllを実行しようとするプログラムがあります

Start.c

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>

typedef int (__stdcall* function)();

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){
    HINSTANCE hGetProcIDDLL = LoadLibrary("OpenLabyrinth.dll");
    if(!hGetProcIDDLL){
        printf("Couldn't find the library: %d", GetLastError());
        return 1;
    }
    function run = (function) GetProcAddress(hGetProcIDDLL, "run");
    if(!run){
        printf("Couldn't find the function: %d", GetLastError());
        return 1;
    }
    run();
    return 0;
}

後でLabyrinth.exeにコンパイルされます

アプリケーションを実行すると、LoadLibrary エラー コード 126 が表示されます。Google エラー 126 を試してみたところ、.dll に依存関係が必要であることがわかりました。

で確認したProcess Monitorところ、プログラムによって実行されたすべての操作が成功していることがわかりましたが、コード 1 で返されました。

しかし、私がそれを使ってそれをチェックしたとき、私Dependency Walkerは多くの不足しているファイルを示しました. それらはすべて または のいずれAPI-MS-WIN-CORE-somethingEXT-MS-WIN-somethingでした。

エラーの原因は何ですか?

4

1 に答える 1