File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Java and DLL's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java and DLL Watch "Java and DLL New topic

Java and DLL's

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1562
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

Joined: Aug 31, 2004
Posts: 11343

This is a little advanced for the beginners forum, so I'm promoting this to the intermediate forum.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
marc weber

Joined: Aug 31, 2004
Posts: 11343

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

    Joined: Oct 10, 2002
    Posts: 77
    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
    Peter Chase
    Ranch Hand

    Joined: Oct 30, 2001
    Posts: 1970
    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.

    Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
    Timothy Wall

    Joined: Sep 14, 2002
    Posts: 14
    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

    Joined: Aug 16, 2005
    Posts: 15082

    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.

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    I agree. Here's the link:
    subject: Java and DLL's
    It's not a secret anymore!