4

I'm a java newbie and I'm trying to load a delphi dll, and call functions from it.

Already tried in php using winbinder but it seems to be useless: reloading dll in winbinder (php gui) crashes program

Anyway I have this simple java code, and I can't figure out how to make it work. There are some examples over the internet, but none seems to be working for me.

Dll is 32bit, so is my windows, jdk and Eclipse. Simples function to use would be GetDllVersion. I would really apriciate any help.

I can't even load it, here is first error (there are couple popups following):

enter image description here

Here is the code:

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.*;

public class Main {

      static {
        try {
            System.load("C:/workspace/XmlDownlaoder/xxxxxxxDLL.dll");
        } catch (UnsatisfiedLinkError e) {
          System.err.println("Native code library failed to load.\n" + e);
          System.exit(1);
        }
      }

      public static void main(String argv[]) 
      {
        //how to call functions here? - there will be many functions, and final one should generate xml in return

      }
    }

EDIT: Native code library failed to load - this doesn't show on console.

Community
  • 1
  • 1
baron_bartek
  • 1,073
  • 2
  • 20
  • 39

1 Answers1

1

Don't load your DLL by hand, let JNA do the grunt work for it.

There are quite a few good resources when you search for Delphi JNA.

A few relevant Stack Overflow questions that explain some of the things you will probably bump into:

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 1
    None of this will help. The DLL initialization is raising a Delphi exception. – David Heffernan May 11 '13 at 23:08
  • Thx for this info. Any ideas how to handle this? Since I'm Java newbie maybe it would be easier to become C++/c# Newbie :) - I ask becouse I have no experience with dll nor C – baron_bartek May 12 '13 at 14:07
  • 1
    If it also fails loading in other environments, then the best approach is to start trying to load it from a simple Delphi application, then use Delphi to see why it fails to load. – Jeroen Wiert Pluimers May 13 '13 at 07:25