I'm trying to get started with calling Windows APIs using Kotlin/Native. So far, I can get some file metadata:
memScoped {
CoInitialize(null, 0)
val fileInfo = alloc<SHFILEINFOA>()
// flags: ICON, DISPLAYNAME, TYPENAME, ICONLOCATION, SMALLICON
SHGetFileInfo("C:\\path\\to.file", 0, fileInfo.ptr, 0, 5889)
println(fileInfo.szDisplayName.toKString()) // prints the file name
println(fileInfo.szTypeName.toKString()) // prints the file type
val iconInfo = alloc<ICONINFO>()
GetIconInfo(iconInfo, fileInfo.hIcon.ptr)
println(iconInfo.hbmColor) // prints some CPointer value
println(iconInfo.hbmMask) // prints some CPointer value
}
I can pass those HBITMAP
s into GetDIBits
:
val bitmap = alloc<BITMAPINFO>()
val bytes: COpaquePointerVar = alloc() // ??
GetDIBits(GetDC(null), iconInfo.hbmColor /* or iconInfo.hbmMask */, 0, UInt.MAX_VALUE, bytes.ptr, bitmap.ptr, 0)
println(bytes) // a NativePointed value
Am I going in the right direction? I'm not sure. I want to get the image bytes, so I can then do further processing.
The documentation doesn't give me any useful information.