je sais que ce probleme a été traité mainte et mainte fois, mais aucun des posts que j'ai trouvé n'a resolu mon probleme.
voici ma classe :
ensuite j'ai generé le .h a l'aide de javah.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 public class Test{ public Test(){ } static{ System.loadLibrary("sample"); } private static native void SomeFunction(); public static void main(String[] args) { Test.SomeFunction(); } }
le code de ma dll est le suivant:
et la a l'execution il lève une UnsatisfiedLinkError exception disant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #include <windows.h> #include "Test.h" #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT #endif // a sample exported function JNIEXPORT void JNICALL Java_Test_SomeFunction(JNIEnv *env, jobject obj) { MessageBoxA(0, "merde", "DLL Message", MB_OK | MB_ICONINFORMATION); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: // attach to process // return FALSE to fail DLL load break; case DLL_PROCESS_DETACH: // detach from process break; case DLL_THREAD_ATTACH: // attach to thread break; case DLL_THREAD_DETACH: // detach from thread break; } return TRUE; // succesful }
j'ai meme essayé de declarer la dll 'naked' mais rien ne change.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\New Folder (2)\sample.dll: %1 is not a valid Win32 application at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:992) at Test.<clinit>(Test.java:8)
si quelqu'un a une idee je suis preneur.
merci d'avance.
Partager