hi,
first sorry if i this question in wrong place and i’m beginner in kotlin.
last night i try tutorial from https://kotlinlang.org/docs/tutorials/native/dynamic-libraries.html and it work perfectly. but then i try to call *.dll file from kotlin native it self but always get error or wrong output. can anyone tell me how to call method or property in that *dll file or point me where to find the answer ?
thank you.
here is my project directory layout :
/src
/src/main
/src/main/kotlin
/src/main/kotlin/HelloDll.kt
/src/main/resource/
/src/main/resource/libnative_symbols-build/
/src/main/resource/libnative.dll
/src/main/resource/libnative.lib
/src/main/resource/libnative_api.h
/src/main/resource/libnative_symbols.def
/src/main/resource/libnative_symbols.dll
/src/main/resource/libnative_symbols.klib
/src/main/resource/usedll.exe
here is my code that call method or property in .dll file :
import kotlinx.cinterop.
import platform.posix.*
import libnative_symbols.*
/*
these is command i call to compile source :
cinterop -def libnative_symbols.def -compilerOpts -I./ -o libnative_symbols
kotlinc-native ..\kotlin -l libnative_symbols -linker-options libnative.lib -o usedll
*/
fun main (args : Array<String>) {
val lib : CPointer<libnative_ExportedSymbols>? = libnative_symbols()
// val ref = libnative_ExportedSymbols(lib.rawValue);
var str : String? = "This is how to use dll from kotlin native"
var resp : CPointer<ByteVar>? = lib!!.pointed.kotlin.root.example.get_globalString!!.reinterpret()
var path : CPointer<ByteVar>? = getenv("PATH")
var pathStr : String = path?.toKString() ?: ""
println("input : " + str)
println("output : " + resp!!.toKString())
println("path : " + pathStr)
}