• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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: 22850
132
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: 22850
132
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic