Andrei Marshalov
06/14/2019, 11:07 AMsomeFunctionFromC(data: kotlinx.cinterop.CValuesRef<libmylib.GByteVar /* = kotlinx.cinterop.UByteVarOf<libmylib.GByte /* = kotlin.UByte */> */>?)
So, i tried to use ‘cstr’ how it described here (https://kotlinlang.org/docs/tutorials/native/mapping-strings-from-c.html):
val kotlinString = "qwerty"
someFunctionFromC(kotlinString.cstr)
but i get type mismatch:
Type mismatch:
Required : CValuesRef<GByteVar /* = UByteVarOf<GByte /* = UByte */> */>?
Found : CValues<ByteVar /* = ByteVarOf<Byte /*>
So i need to pass in C function not const char* cstring
, but const unsigned char* cstring
Solution that i found (https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md):
kotlinString.toUtf8().toUByteArray().usePinned { kString ->
someFunctionFromC(kString.adressOf(0))
}
It work, but doesn’t look well. Maybe someone can suggest a better way?msink
06/14/2019, 11:13 AMkotlinString.cstr.convert()
dosn't work too?Andrei Marshalov
06/14/2019, 11:29 AMolonho
06/14/2019, 12:10 PMkotlinString.cstr as CValuesRef<GByteVar>
may workAndrei Marshalov
06/14/2019, 12:35 PM