Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JNI: Error shown by both CL and Bcc32 while making DLL file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make JNI object that is interfacing parallel port using DOS.h inportb
& outportb functions.
I have the following java files.
------------------------------
Dimmer.java
------------------------------
class Dimmer
{
int intensity;

public Dimmer(int intensity)
{
this.intensity=intensity;
System.loadLibrary("NativeDimmer");
}
public native void applyIntensity();
}
------------------------------
DimmerDemo.java
------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class DimmerDemo extends JFrame implements ActionListener,ChangeListener
{
JSlider slider;
JButton exit;
Dimmer d;
RunnerThread runner;

public static void main(String[] args)
{
JFrame frame = new DimmerDemo();
frame.show();
}
public DimmerDemo()
{
setSize(200,100);
setTitle("Project DAS: Device interface Demo");
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane= getContentPane();
contentPane.setLayout(new GridLayout(3,1));
contentPane.add(new JLabel(" Light-Intensity "));
slider = new JSlider(0,10,5);
slider.addChangeListener(this);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(2);
slider.setMinorTickSpacing(1);
slider.putClientProperty("JSlider.isFilled",Boolean.TRUE);
contentPane.add(slider);

exit=new JButton(" Exit ");
exit.addActionListener(this);
contentPane.add(exit);
d=new Dimmer(5);
runner=new RunnerThread("runner",d);
runner.start();
}
public void stateChanged(ChangeEvent ce)
{
JSlider temp=(JSlider)ce.getSource();
d.intensity=slider.getValue();
}
public void actionPerformed(ActionEvent ae)
{
Object source=ae.getSource();
if(source==exit)
{
d.intensity=-1;
runner.stop();
try
{
runner.join();
}catch(InterruptedException e){}
System.exit(0);
}
}

}
class RunnerThread extends Thread
{
Dimmer dimmer;
public RunnerThread(String name,Dimmer dimmer)
{
super(name);
this.dimmer=dimmer;
}

public void run()
{
try
{
dimmer.applyIntensity();
}
catch(Exception e) { }
}
}
-----------------------------
NativeDimmer.cpp
------------------------------
#include <stdio.h>
#include <jni.h>
#include "Dimmer.h"
#include <dos.h>
#define OUTPORT 0x378
#define INPORT 0x379
JNIEXPORT void JNICALL Java_Dimmer_applyIntensity
(JNIEnv *env, jobject obj)
{
jclass cls;
jfieldID fid;
jint i;
unsigned char toggle=0x7f;
cls=(*env)->GetObjectClass(env,obj);
fid=(*env)->GetFieldID(env,cls,"intensity","I");
i=(*env)->GetIntField(env,obj,fid);

while(i!=-1){
i=(*env)->GetIntField(env,obj,fid);
printf("\ri=%2d",i);
while(inportb(INPORT)!=toggle);
toggle^=0x80;
while(inportb(INPORT)!=toggle);
outportb(OUTPORT,0x00);
delay(10-i);
outportb(OUTPORT,0x01);
}
}
problem:
when i try to compile and make a dll through
CL command (dll maker From Microsoft)
CL -Ic:\jdk1.3\include -Ic:\jdk1.3\include\win32 -LD NativeDimmer.cpp -FeNativeDimmer.dll

it shows errors saying
_inportb() not found DOS.h
_outportb() not found in DOS.h
_delay() not found in dos.h
when i tried the dos.h provided by TurboC
the CL replied with errors showing problems
with this DOS.H which contains the functions
i require namely inportb(),outportb() & delay()
when the same was tried with bcc32 dll maker
from borland it showed errors in jni.h
bcc32 -Ic:\jdk1.3\include -Ic:\jdk1.3\include\win32 -WD NativeDimmer.cpp -oNativeDimmer.dll
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I am also trying the same thing
Actually, I am trying to acces parallel port thru my Java program using JNI and we require to make a dll to use the .c or .cpp file and outportb() fn shows an error...

I used CL /LD nativedemo.c
nativedemo.obj
Creating library nativedemo.lib and object nativedemo.exp
nativedemo.obj : error LNK2001: unresolved external symbol _outportb()
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbo
nativedemo.exe : fatal error LNK1120: 2 unresolved externals

can some1 explain this...
 
    Bookmark Topic Watch Topic
  • New Topic