0

Can I change wallpaper of windows 7 using Java code?

Here's my code:

public class Changer {
    /**
     * @param args
     */
    public static native int SystemParametersInfo(int uiAction,int uiParam,String pvParam,int fWinIni);

    static
    {
        System.loadLibrary("user32");
    }

    public int Change(String path)
    {
       return SystemParametersInfo(20, 0, path, 0);
    }

    public static void main(String args[])
    {
        String wallpaper_file = "D:\\Photos\\walli\\dream girls\\jes54d.jpeg";
        Changer mychanger = new Changer();
        mychanger.Change(wallpaper_file);
    }
}

This code in Eclipse IDE failed. I am getting this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.changer.Changer.SystemParametersInfo(IILjava/lang/String;I)I
    at com.changer.Changer.SystemParametersInfo(Native Method)
    at com.changer.Changer.Change(Changer.java:18)
    at com.changer.Changer.main(Changer.java:25)

I am new to Java and couldn't figure out what would be the possible solution.

Thanks in advance.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
user2520736
  • 1
  • 1
  • 1

1 Answers1

2

Function call SystemParametersInfo(20, 0, path, 0) is wrong. It expects SystemParametersInfo(UINT_PTR uiAction, UINT_PTR uiParam, String pvParam, UINT_PTR fWinIni).

Refer accepted answer here.

You can get JNA from here. And refer javadocs here.

Community
  • 1
  • 1
Jaydeep Patel
  • 2,394
  • 1
  • 21
  • 27