0

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 HBITMAPs 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.

Jorn
  • 20,612
  • 18
  • 79
  • 126
  • This seems backwards - normally you have a desire to achieve something and then investigate how to get there. – 500 - Internal Server Error Feb 17 '23 at 21:52
  • @500-InternalServerError I have a desire to get the icon data into a format I can use. Is something unclear about the question? – Jorn Feb 17 '23 at 21:55
  • As an example, here's [an answer](https://stackoverflow.com/questions/24720451/save-hbitmap-to-bmp-file-using-only-win32) that shows how to save a bitmap from a handle (what you have here) to a file. – 500 - Internal Server Error Feb 17 '23 at 22:15

0 Answers0