How can I call Windows api such `GetVersion`, `Get...
# kotlin-native
a
How can I call Windows api such
GetVersion
,
GetSerialNumber
? I have not found these functions.
a
You can try to use cinterop to generate bindings onto the
sysinfoapi.h
header including them, and then use it.
r
GetVersion()
exists in
platform.windows
. Apparently deprecated in newer Windows versions though according to https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversion
a
Thanks! I've created
sysinfoapi.def
and have found GetVersion() etc
But result....
Copy code
val version = GetVersion().toLong()
        val version0 = version.toByte()
        val version1 = (version / 256).toByte()
        val version2 = (version / 65536).toShort()
        println("$version/${version.toString(16)} - ${version0}.${version1}.${version2}")
Result:
602931718/23f00206 - 6.2.9200
But...
Copy code
C:\>cmd /c ver

Microsoft Windows [Version 10.0.18363.836]
Why 6.2 instead of 10.0?
a
This can be the reason. From the Microsoft documentation above:
Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2).
a
But new methods will not return version - olny "Is...Or...". How can I get windows version?
a
It seems to be a Windows API question rather than a Kotlin/Native one. I’ve read through this, and maybe you can use this approach: to get system version via the file information of your system DLLs. Why wouldn’t you try going with
IsWindows10OrGreater
?
a
Thank you!