Accessing DLL in Java doesn't work - really it DOESN'T !!!

Hi,

I've got big troubles accessing a DLL in Java - almost for one week !!!

I want to call some methods from the LDCNLIB.DLL (www.logosolinc.com -> Software)

First, I tried to access the file via JNI ->

Exception in thread "main" java.lang.UnsatisfiedLinkError: LdcnInit

at Test.LdcnInit(Native Method)

at Test.main(Test.java:11)

Of Course, the DLL is loaded, everything seems fine.

I tried to create header files, I tried SWIG, JNIWrapper, JACE, JAWIN, ... Nothing!!!

I just want to call this method: "int count = LdcnInit("COM1", 19200);"

Can anybody help me? Please (don't be angry with me), just tell me what to do, no links to tutorials or documentations - I ALREADY READ THEM ALL!!!

Thanks

Torsten

[791 byte] By [torsten_luchsa] at [2007-10-3 9:21:28]
# 1
You have to create a "wrapper" DLL that calls the existing DLL. the function of the wrapper is to meet the java native interface specification, and give you an entry point into the existing DLL.This is, in fact, discussed in the Sun JNI tutorial.
bschauwejavaa at 2007-7-15 4:34:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi,

I had no problem at all to access this lib with JNative.

Here is a sample code.

package org.xvolks.test.Ldcnlib;

import org.xvolks.jnative.JNative;

import org.xvolks.jnative.Type;

import org.xvolks.jnative.exceptions.NativeException;

public class Test {

public static void main(String[] args) throws NativeException, InterruptedException, IllegalAccessException {

//System.setProperty("jnative.loadNative", "E:\workspace\JNativeCpp\Win32_Release\libJNativeCpp.dll")

for(String s : JNative.getDLLFileExports("C:\\Documents and Settings\\Administrateur\\Bureau\\ldcnlib\\Ldcnlib.dll")) {

System.err.println(s);

}

System.load("C:\\Documents and Settings\\Administrateur\\Bureau\\ldcnlib\\Ldcnlib.dll");

JNative LdcnInit = new JNative("Ldcnlib.dll", "LdcnInit");

LdcnInit.setRetVal(Type.INT);

LdcnInit.setParameter(0, "COM1");

LdcnInit.setParameter(1, 19200);

LdcnInit.invoke();

System.err.println("LdcnInit returned "+LdcnInit.getRetValAsInt());

}

}

The output was as expected :

AddArcSeg

AddLineSeg

AddPathPoints

ClearSegList

FixSioError

GetComPort

GetSioError

IOSynchOutput

InitPath

IoBitDirIn

IoBitDirOut

IoClrOutBit

IoGetADCVal

IoGetBitDir

IoGetOutputs

IoGetPWMVal

IoGetStat

IoGetTimerMode

IoGetTimerSVal

IoGetTimerVal

IoInBitSVal

IoInBitVal

IoOutBitVal

IoSetOutBit

IoSetOutputs

IoSetPWMVal

IoSetSynchOutput

IoSetTimerMode

IsBusy

LdcnChangeBaud

LdcnDefineStatus

LdcnFullInit

LdcnGetGroupAddr

LdcnGetModType

LdcnGetModVer

LdcnGetStat

LdcnGetStatItems

LdcnGroupLeader

LdcnHardReset

LdcnInit

LdcnNoOp

LdcnReadStatus

LdcnResetDevice

LdcnRestoreNetwork

LdcnSendCmd

LdcnSetGroupAddr

LdcnShutdown

LdcnSynchInput

MaxStepPeriod

MinStepPeriod

PathGetVelocity

PathTime

SegmentsInBuffer

ServoAddPathPoints

ServoClearBits

ServoEEPROMCtrl

ServoGetAD

ServoGetAD10

ServoGetAux

ServoGetCmdAcc

ServoGetCmdAdc

ServoGetCmdAdc10

ServoGetCmdPos

ServoGetCmdPwm

ServoGetCmdVel

ServoGetGain

ServoGetHome

ServoGetHomeCtrl

ServoGetInport1

ServoGetInport2

ServoGetInport3

ServoGetIoCtrl

ServoGetMoveCtrl

ServoGetNPoints

ServoGetOutport1

ServoGetOutport2

ServoGetOutport3

ServoGetOutport4

ServoGetPError

ServoGetPos

ServoGetSDMode

ServoGetServoInit

ServoGetStat

ServoGetStopCtrl

ServoGetVel

ServoInitPath

ServoLoadTraj

ServoLoadTraj10

ServoResetPos

ServoResetRelHome

ServoSetFastPath

ServoSetGain

ServoSetHoming

ServoSetOutputs

ServoStartMotion

ServoStartPathMode

ServoStopMotor

SetFeedrate

SetOrigin

SetPathParams

SetTangentTolerance

SimpleMsgBox

SioChangeBaud

SioClose

SioClrInbuf

SioGetChars

SioOpen

SioPutChars

SioTest

StepGetAD

StepGetCmdAcc

StepGetCmdPos

StepGetCmdST

StepGetCmdSpeed

StepGetCtrlMode

StepGetEmAcc

StepGetHoldCurrent

StepGetHome

StepGetHomeCtrl

StepGetIObyte

StepGetInbyte

StepGetMinSpeed

StepGetMvMode

StepGetOutputs

StepGetPos

StepGetRunCurrent

StepGetStat

StepGetStepPeriod

StepGetStepTime

StepGetStopCtrl

StepGetThermLimit

StepLoadTraj

StepLoadUnprofiledTraj

StepResetPos

StepSetHoming

StepSetOutputs

StepSetParam

StepStopMotor

StepTime2StepsPerSec

StepsPerSec2StepTime

StepsPerSec2mSecPerStep

CPPdebugHook

mSecPerStep2StepsPerSec

LdcnInit returned 0

--Marc (http://jnative.sf.net)

mdentya at 2007-7-15 4:34:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi guys,

thanks a lot. The JNative code works fine, but it's not that convenient to invoke all these "setter-methods" to do just one dll-call. How can I call functions with BOOL, byte, ... values (e.g. BOOL LdcnSendCmd(byte addr, byte cmd, char *datastr, byte n);) ?

@bschauwejava : Could you please give me an concrete example to do this. I was not able to get it working!

torsten_luchsa at 2007-7-15 4:34:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
You cannot call C subroutines from java and pass the kind of parameters you are talking about.Code: Post what you tried that didn't work. maybe we can help.
bschauwejavaa at 2007-7-15 4:34:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...