• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Change Desktop background using jna

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Posts: 7113
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's try moving you to another forum.
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic