In the code below I get an error, and somehow I couldn't find information to fix it. Sorry for any misunderstandings.
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
// JNA infrastructure import libs.Kernel32;
// Proxy interface for kernel32.dll
public interface JnaTests extends Library {
public boolean Beep(int FREQUENCY , int DURATION );
static Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
static void toMorseCode(String letter) throws Exception {
for (byte b : letter.getBytes()) {
kernel32.Beep(1200, ((b == '.') ? 50 : 150));
Thread.sleep(50);
}
}
public static void main(String[] args) throws Exception {
String helloWorld[][] = { {"....", ".", ".-..", ".-..", "---"}, {".--", "---", ".-.", ".-..", "-.."}};
for (String word[] : helloWorld) {
for (String letter : word) {
toMorseCode(letter);
Thread.sleep(150);
}
Thread.sleep(350);
}
}
}
Thanks for the answers.
Finally I found that there should be an Interface (Kernel32) in a separated file.
This was mentioned in the community documentation, however some .dll worked also without Interface e.g. User32.dll .
package com.sun.jna.platform;
import com.sun.jna.Library;
//@author windows-System
public class win32 {
public interface Kernel32 extends Library {
boolean Beep(int frequency, int duration);
// ... (lines deleted for clarity) ... }
}
}
Main-file
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
// JNA infrastructure import libs.Kernel32;
// Proxy interface for kernel32.dll
public class JnaTests {
private static Kernel32 kernel32 = (Kernel32)
Native.loadLibrary ("kernel32", Kernel32.class);
private static void toMorseCode(String letter) throws Exception {
for (byte b : letter.getBytes()) {
kernel32.Beep(1200, ((b == '.') ? 50 : 150));
Thread.sleep(50);
}
}
public static void main(String[] args) throws Exception {
String helloWorld[][] = { {"....", ".", ".-..", ".-..", "---"},
{".--", "---", ".-.", ".-..", "-.."}};
for (String word[] : helloWorld) {
for (String letter : word) {
toMorseCode(letter);
Thread.sleep(150);
}
Thread.sleep(350);
}
} }