gpt4 book ai didi

Java:JNA SystemParametersInfo 参数类型

转载 作者:行者123 更新时间:2023-11-30 05:05:48 29 4
gpt4 key购买 nike

我才开始尝试 JNA,并且一直尝试在没有异常的情况下调用此函数
原生原型(prototype):

BOOL WINAPI SystemParametersInfo(
__in UINT uiAction,
__in UINT uiParam,
__inout PVOID pvParam,
__in UINT fWinIni
);

我建议了这样的 JNA 等效项:

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[])

最佳答案

解决了我自己的映射问题:

    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 参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5132431/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com