Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wanted: Help with using JNI/JNA for Native Win32/x86-64.

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm trying to use https://github.com/jeffheaton/jna-example and https://www.heatonresearch.com/2018/10/02/jna-quickstart.html as a guide and the sample works.

I've tried adding this program generated ChatGPT and I'm getting a stack trace



I'm getting this error in IntelligJIdea when using Jeff Heaton's pom.xml file.



I think I need to enhance that pom.xml somehow.

Thanks

Siegfried

 
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think the issue lies in your dependencies. If it were you'd get compiler errors. I think it's more with how you load the libraries.

All examples I've seen use Kernel32.INSTANCE and User32.INSTANCE. These call Native.load instead of Native.loadLibrary (see Kernel32 and User32). The latter is now deprecated. The calls to load also use some default options.
 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:I don't think the issue lies in your dependencies. If it were you'd get compiler errors. I think it's more with how you load the libraries.

All examples I've seen use Kernel32.INSTANCE and User32.INSTANCE. These call Native.load instead of Native.loadLibrary (see Kernel32 and User32). The latter is now deprecated. The calls to load also use some default options.



Shame on me! I should have studied Jeff Heatton's working code more closely and trusted ChatGPT less.

My apologies for being sloppy.

Whoa! This is kinda tedious writing the signature for each function you want to call be fore you call it. Surely, someone else has already done this for Kernel32?  Anyone know of where I might find this?
 
Rob Spoor
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless I'm misreading what you're asking for, the Kernel32 interface I linked to has a lot of methods already. If you miss any, you can always extend the interface, like I've done here: https://github.com/robtimus/windows-registry/blob/master/src/main/java/com/github/robtimus/os/windows/registry/Advapi32Extended.java.
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic