How to get argc and argv from main function

For C function int main(int argc, char argv[]) { / … */ }

How can I get argc and argv fun main(vararg args: String) {
val argc = alloc().apply { value = args.size }.ptr
val argv = ??
gtk_init(argc, argv)
}

//fun gtk_init(argc: CValuesRef?, argv: CValuesRef<CPointerVar<CPointerVar>>?): Unit

Hello! Try something like

        val argc = alloc<IntVar>()
        argc.value = args.size
        val argv = alloc<CPointerVar<CPointerVar<ByteVar>>>()
        argv.value = args.map { it.cstr.ptr }.toCValues().ptr
        gtk_init(argc.ptr, argv.ptr)
1 Like

But Kotlin launcher.cpp skips argv[0] which is the binary name.

thanks… I’m learning it more. I’m also looking for book. if you know please suggest me name.

Yes, one should extend args Array with the binary name, putting it in the first place. I thought it was out of the question scope, thank you for the adjustment.