Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Java and DLL's

 
Ranch Hand
Posts: 2153
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I access a DLL and invoke its methods from a java class? the DLL was written in Visual FoxPro with a class definition OLEPUBLIC which should be accessible to any automation client.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a little advanced for the beginners forum, so I'm promoting this to the intermediate forum.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never tried using a native method, but see if these pages help...
  • Tell the Java VM to Load the DLL
  • Making Native Windows API calls from within a Java Application

  • [ July 18, 2007: Message edited by: marc weber ]
     
    Ranch Hand
    Posts: 77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Here is a post on "How to Build A DLL and Call It From Another C Program, using MS VC++ 6.0"

    it is not on Visual Fox Pro,but I hope it helps

    http://ulasergin.blogspot.com/2006/02/how-to-build-dll-and-call-it-from.html
     
    Ranch Hand
    Posts: 1970
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You cannot call arbitrary functions in a DLL directly from Java.

    You'll need to write a Java class, to define the interface of your DLL. Some of the methods of this class would be declared native. The native methods would be implemented in C or C++ and would be compiled into another DLL. Your Java code need to load this DLL, maybe with System.loadLibrary().

    The native implementation of these methods would translate the data between the Java types and whatever types your FoxPro DLL uses. The native implementation would also be responsible for loading the FoxPro DLL.
     
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If it's a COM DLL, then either JACOB or JAWIN will let you access the DLL without any JNI programming.

    If it's a straight C API exported by the DLL, then JNA should do the trick (again, without any JNI programming).
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    JNI is the standard API to call native code, such as functions in a DLL. However, JNI can be hard to use and may require you to write some C or C++ code.

    There are some libraries to make working with native code easier. Have a look at these ones:

    NativeCall - Call native methods from Java without JNI
    J/Invoke - The easy JNI replacement

    These allow you to call native functions without having to write native wrapper functions yourself.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic