使用JNA(Java)进行Windows缩略图预览

时间:2010-05-12 18:43:55

标签: java winapi jna dwm

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)

给了我

# 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]

我有一种感觉,我完全错了,但是挖掘文档让我无处可去。

1 个答案:

答案 0 :(得分:3)

第3个参数是一个“out”参数,需要是指向句柄的指针,而不是句柄本身。所以,像

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