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.

3
  • The DLL is raising an exception in its DllMain. That's initialization time. Can you load it from anoth environment. For example Delphi. Or C++. Commented May 11, 2013 at 23:09
  • 1
    forget about java until you can write a C program that will load the dll Commented May 12, 2013 at 16:07
  • I was kinda expecting that coming, and I needed to hear (read) id :) . Thanx. I try my luck with c++. Commented May 12, 2013 at 19:09

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

3 Comments

None of this will help. The DLL initialization is raising a Delphi exception.
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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.