• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java and DLL's

 
Steve Dyke
Ranch Hand
Posts: 1643
1
  • Mark post as helpful
  • send pies
  • 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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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 ]
     
    Ulas Ergin
    Ranch Hand
    Posts: 77
    • Mark post as helpful
    • send pies
    • 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
     
    Peter Chase
    Ranch Hand
    Posts: 1970
    • Mark post as helpful
    • send pies
    • 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.
     
    Timothy Wall
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • 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).
     
    Jesper de Jong
    Java Cowboy
    Saloon Keeper
    Posts: 15441
    41
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic