Bonjour;

je veux appeler une fonction écrite en c dans mon programme java;
j'ai écrit mon code C:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
#include <stdio.h>
main()
{
	printf("hello ");
}
void mamethode()
{
	printf("hello from me");
}
j'ai compiler mon C fichier:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
    gcc -I %JAVA_HOME%\include -I %JAVA_HOME%\include\win32 -c HELLO.c
j'ai générer mon dll :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
    gcc -shared -Wl,--kill-at HELLO.o -o HELLO.dll
et ma classe est:
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
 
package org.test;
 
import com.sun.jna.Native;
import com.sun.jna.Library;
 
public class Test {
public interface CInterface extends Library {
	public void main();
 
	public void mamethode();
}
	public static void main(String[] args) {
		String mytext = "Hello World!";
 
		String libName = "C:\\dll\\HELLO.dll";
		// if (System.getProperty("os.name").contains("Windows")) {
		// libName = "msvcrt";
		// }
 
		// Loading dynamically the library
 
		CInterface demo = (CInterface) Native.loadLibrary(libName,
				CInterface.class);
 
		demo.mamethode();
 
	}
}
mais j'obtient l'erreur suivantes:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\dll\HELLO.dll': The specified module could not be found.
 
	at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
	at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
	at com.sun.jna.Library$Handler.<init>(Library.java:123)
	at com.sun.jna.Native.loadLibrary(Native.java:255)
	at com.sun.jna.Native.loadLibrary(Native.java:241)
	at org.test.Test.main(Test.java:17)