tags:

views:

104

answers:

1

Hi, I am using JNA to access a custom DLL which seems to be using the FAR PASCAL Calling Conventions, but the JVM crashes every time i try to access it.

Development Guide of the dll says: BOOL FAR PASCAL GetIomemVersion(LPSTR);

And Dependency Walker tells me: _GetIomemVersion@4

public class PebblePrinter{

public interface Iomem extends StdCallLibrary { boolean _GetIomemVersion(String version); }

String version;  
Iomem INSTANCE;  
StdCallFunctionMapper myMapper;

public PebblePrinter(){ HashMap optionMap = new HashMap(); myMapper = new StdCallFunctionMapper(); optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper); INSTANCE = (Iomem)Native.loadLibrary("iomem", Iomem.class,optionMap); } public String getIomemVersion(){ INSTANCE._GetIomemVersion(version); return version; } }

With C# code it works well using

[DllImport("iomem.dll", EntryPoint = "_GetIomemVersion@4")]
public static extern bool GetIomemVersion(IntPtr version);

Can you tell me what i am doing wrong? Thanks in advance!!!

A: 

Problem solved,

I've just used the wrong parameter .. GetIomemVersion needs a Pointer

boolean _GetIomemVersion(Pointer version);


public String getIomemVersion(){    
   Memory m = new Memory(1024);
   Pointer x = m.getPointer(0);
   INSTANCE._GetIomemVersion(x);
   return x.getString(0);   
}
Barret85