Hi there,
How did everything start?
I thought myself it would be nice to create a XMas Slideshow in
Java as I'm still learning from O'Rielley 2nd Java SE 2nd edition and didn't understand very well how to use interfaces(not GUI thing...for
polymorphism).
Well, I found out the only way I can interact with window's desktop is via an Windows API and that I need to gain access to windows shared libraries...and the only way is Jna...if I want to use 100% Java code...
I found out there is a function called SystemParametersInfo that I should use in order to change desktop wallpaper from my java program.
Well...at first I created my class and an interface. This interface extends StdCallLibrary(which I don't know what's for..maybe for calling back C++ library function SystemParametersInfo but not sure).
This is my code and works well
But there are many thing I don't understand:
1) Why is the system returning Object ...I mean...why I can't just say
and I must cast?
2) Why is the mapping mandatory? What does mapping do...what's for?
If I get rid of mapping part and use the 2 args loadLibrary signature method I get this error :
Exception in
thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'SystemParametersInfo': The specified procedure could not be found.
at com.sun.jna.Function.<init>(Function.java:212)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:541)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:518)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:504)
at com.sun.jna.Library$Handler.invoke(Library.java:220)
at com.sun.proxy.$Proxy0.SystemParametersInfo(Unknown Source)
at WallpaperChanger.main(Switch.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
...Why on hell?? Why is this mapping so important?