Java:JNA SystemParametersInfo 参数类型

标签 java pointers jna

我才开始尝试 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/

相关文章:

c - c中的指针作为结构体变量

java - 如何使用最少的内存在哈希集中存储字符串

c - 如何修复我的代码以读取返回指向结构的指针的函数中的字符串

c++ - typedef int* intptr 或 typedef int *intptr;

java - 为什么当调用带有回调的方法时我没有得到任何输出?

java - 从 JNA 调用读取 String[] 失败

java - EJB调度中如何设置定时器值?

java - EnhancedPatternLayout 和 PatternLayout 之间的主要区别是什么?

java - 使用字符串列表作为组合框的来源

android - 我如何使用 JNA 从 Android 调用 C/C++ 代码?