JNA loadLibrary()方法显示参数错误

时间:2019-03-27 08:35:07

标签: java jna

我想使用Java将图像设置为桌面墙纸。我在互联网上找到了一个解决方案,但是它不起作用。我不明白这是怎么回事。

这是对我说的话? 你能帮我吗?

enter image description here

import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.UINT_PTR;
import com.sun.jna.win32.*;
import java.util.HashMap;

public class WallpaperSetter {

        public interface SPI extends StdCallLibrary {

            //from MSDN article
            long SPI_SETDESKWALLPAPER = 20;
            long SPIF_UPDATEINIFILE = 0x01;
            long SPIF_SENDWININICHANGE = 0x02;

            //Here is the problem
            SPI INSTANCE = (SPI) Native.loadLibrary("user32", SPI.class, new HashMap<Object, Object>() {
                {
                    put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
                    put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
                }
            });

            boolean SystemParametersInfo(
                    UINT_PTR uiAction,
                    UINT_PTR uiParam,
                    String pvParam,
                    UINT_PTR fWinIni
            );
        }

        public static void setWallpaper(String image_url) {
            String path = image_url;

            SPI.INSTANCE.SystemParametersInfo(
                    new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),
                    new UINT_PTR(0),
                    path,
                    new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));

        }

}

1 个答案:

答案 0 :(得分:0)

好的。将Map<Object, Object>更改为Map<String, Object>