简体   繁体   中英

Windows thumbnail preview with JNA (Java)

W32API.HWND targetHwnd = User32.INSTANCE.FindWindow("SunAwtFrame", "Frame")
W32API.HWND sourceHwnd = User32.INSTANCE.FindWindow("triuiScreen", "EVE")
W32API.HANDLE thumbnailH = new W32API.HANDLE()

NativeLibrary dwm = NativeLibrary.getInstance("dwmapi")
dwm.getFunction('DwmRegisterThumbnail').invoke(targetHwnd, sourceHwnd, thumbnailH)

gives me

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x70f34bee, pid=7208, tid=7364
#
# JRE version: 6.0_18-b07
# Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [DWMAPI.DLL+0x4bee]

I have a feeling I'm doing it completely wrong, but digging in documentation got me nowhere.

The 3rd param is an "out" parameter, and needs to be a pointer to the handle, not the handle itself. So, something like

dwm.getFunction("DwmRegisterThumbnail")
  .invoke(targetHwnd, sourceHwnd, new PointerByReference(thumbnailH))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM