Java:JNA SystemParametersInfo参数类型 [英] Java: JNA SystemParametersInfo parameters type
本文介绍了Java:JNA SystemParametersInfo参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是开始尝试JNA,并一直试图在没有异常的情况下调用此函数
原生原型:
I only started to experiment with JNA, and stuck trying to call this function w/o exception
Native prototype:
BOOL WINAPI SystemParametersInfo(
__in UINT uiAction,
__in UINT uiParam,
__inout PVOID pvParam,
__in UINT fWinIni
);
我建议使用等效的JNA:
I've suggested such JNA equivalent:
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
boolean SystemParametersInfo(
UINT_PTR uiAction,
UINT_PTR uiParam,
Pointer pvParam,
UINT_PTR fWinIni
);
public static final int SPI_GETCLEARTYPE = 0x1048;
public static final int SPI_GETDESKWALLPAPER = 0x0073;
}
问题是如何使用指针使用不同的pvParam类型调用它?
例如SPI_GETCLEARTYPE(在BOOL中)和SPI_GETDESKWALLPAPER(在char []中)
And the question is how to call it with different pvParam types using pointer?
for example SPI_GETCLEARTYPE (where it's BOOL) and SPI_GETDESKWALLPAPER (where it's char[])
推荐答案
解决了我自己,因此映射了:
Solved myself so the mapping:
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class,
new HashMap<Object, Object>() {
{
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
}
});
public static final int SPI_GETDESKWALLPAPER = 0x0073;
public static final int SPI_GETSCREENSAVERRUNNING = 114;
boolean SystemParametersInfo(
int uiAction,
int uiParam,
Pointer pvParam,
int fWinIni
);
}
及其用法:
IntByReference intPtr = new IntByReference();
//that's the place where i'm stuck trying to initialize with Pointer constructor
Pointer ptr = new Memory(Pointer.SIZE * 256);
User32.INSTANCE.SystemParametersInfo(User32.SPI_GETSCREENSAVERRUNNING, 0,intPtr.getPointer(), 0);
User32.INSTANCE.SystemParametersInfo(User32.SPI_GETDESKWALLPAPER,256, ptr, 0);
这篇关于Java:JNA SystemParametersInfo参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文