I have never worked with anything "native" before,...
# kotlin-native
n
I have never worked with anything "native" before, only JVM, so I don't know what's possible with K/N. I am wondering: can I interact with an HID device via K/N, or is that is totally out of scope? https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/introduction-to-hid-concepts
o
yes, it is possible, as long, as there’s C API to that, K/N can call it. In case of DDI libs, one may have to write interop definition files, but it is rather straightforward
n
I believe it uses a DLL, but I also see header files. Do you think I need experience working with it before trying to use it in Kotlin? Here is some info on it - I'm not sure what to look for. https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/ There's also another API written in C: https://github.com/signal11/hidapi
o
try ddk.def like that
Copy code
package = ddk
depends = posix windows
headers = wtypes.h minwindef.h cfgmgr32.h hidclass.h hidusage.h hidpi.h hidsdi.h
compilerOpts = -DUNICODE -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -DWINAPI_FAMILY=3 -DOEMRESOURCE \
    -Wno-incompatible-pointer-types -Wno-deprecated-declarations
linkerOpts = -lhid
then
cinterop -def ddk.def -o ddk
and sample like ddk_test.kt
Copy code
import ddk.*
import platform.posix.GUID
import kotlinx.cinterop.*

fun main(args: Array<String>) = memScoped {
   val guid = alloc<GUID>()
   HidD_GetHidGuid(guid.ptr)
   println(guid)
}
then
konanc ddk_test.kt -l ddk
will produce an executable able to work with HID devices. If some declarations are not present - find them and add to
headers
section of the .def file.
n
Hi, luckily every step in this process worked for me! Here is the output I am receiving. I'm not quite sure what to make of it.
Copy code
$ ./program.exe
NativePointed(raw=0x1730a8)
Is this simply the output from the native call? via https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/hidsdi/nf-hidsdi-hidd_gethidguid