Cant use native method: java.lang.UnsatisfiedLinkError: Main.C.C.change(II)J

  c++, java, java-native-interface, native

I’m trying to run a native method that I created but when I try and run my main method I get this error and I’ve got no clue how to fix it, I 100% know my shared library is being loaded.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Main.C.C.change(II)J
    at Main.C.C.change(Native Method)
    at Main.C.C.main(C.java:16)

Here are all the resources:

C.java

package Main.C;

import java.io.File;

public class C {

    public static native long change(int width, int height);

    private static final String absolute = new File("src/Main/C/resolution.dll").getAbsolutePath();

    static {
        System.load(absolute);
    }

    public static void main(String[] args) {
        C.change(1024, 768);
    }

}

Main_C_C.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Main_C_C */

#ifndef _Included_Main_C_C
#define _Included_Main_C_C
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Main_C_C
 * Method:    change
 * Signature: (II)J
 */
JNIEXPORT jlong JNICALL Java_Main_C_C_change
  (JNIEnv *, jclass, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

change.cpp

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

long change(int width, int height) {
    DEVMODE devmode;
    devmode.dmPelsWidth = width;
    devmode.dmPelsHeight = height;
    devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
    devmode.dmSize = sizeof(DEVMODE);

    return ChangeDisplaySettings(&devmode, 0);
}

They were used to create a shared library called resolution.dll which is loaded in C.java, like I said I 100% know that the library is being loaded, and both the file and JVM are compatible.

Any help would be appreciated.

Source: Windows Questions C++

LEAVE A COMMENT