-
Notifications
You must be signed in to change notification settings - Fork 2
/
NativeFromKotlin.kt
32 lines (27 loc) · 1.02 KB
/
NativeFromKotlin.kt
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
import com.sun.jna.Library
import com.sun.jna.Native
interface NativeLibrary : Library {
companion object {
val INSTANCE = Native.load("/native-demo/native-c#.dll", NativeLibrary::class.java) as NativeLibrary
}
fun print_message()
fun add_numbers(x: Int, y: Int): Int
fun subtract_numbers(x: Int, y: Int): Int
fun multiply_numbers(x: Double, y: Double): Double
fun divide_numbers(x: Double, y: Double): Double
fun populate_array(array: DoubleArray, arraySize: Int)
}
fun main() {
val added = NativeLibrary.INSTANCE.add_numbers(7, 2)
val subtracted = NativeLibrary.INSTANCE.subtract_numbers(7, 2)
val multiplied = NativeLibrary.INSTANCE.multiply_numbers(7.0, 2.0)
val divided = NativeLibrary.INSTANCE.divide_numbers(7.0, 2.0)
val array = DoubleArray(5)
NativeLibrary.INSTANCE.populate_array(array, array.size)
NativeLibrary.INSTANCE.print_message()
println(added)
println(subtracted)
println(multiplied)
println(divided)
println(array.contentToString())
}