Help using native methods

  • Thread starter smita b via JavaKB.com
  • Start date
S

smita b via JavaKB.com

I am trying to use native methods in java .Code is like :-

aaa.java :-
class aaa
{ public static void main(String s[])
{ bbb a;
System.out.println("Start");
a = new bbb();
System.out.println("Before xx");
a.xx();
System.out.println("After xx");
}
}

class bbb
{ public native void xx();
public bbb()
{
System.out.println("in bbb");
System.loadLibrary("sss");
}
}


sss.c :-
#include <windows.h>
void *Java_bbb_xx_stub(void * p)
{ MessageBox(0,"Hi","Hi",0);
return p;
}

sss.def :-
LIBRARY sss
EXPORTS
Java_bbb_xx_stub

I have created a sss.dll & aaa.h also.
when using java aaa at command prompt.
I am getting error as :-
Exception in thread "main" java.lang.UnsatisfiedLinkError: xx
at bbb.xx(Native Method)
at aaa.main(aaa.java:9)
What should I do?
 
S

Stefan Schulz

sss.c :-
#include <windows.h>
void *Java_bbb_xx_stub(void * p)
{ MessageBox(0,"Hi","Hi",0);
return p;
}

sss.def :-
LIBRARY sss
EXPORTS
Java_bbb_xx_stub

I have created a sss.dll & aaa.h also.
when using java aaa at command prompt.
I am getting error as :-
Exception in thread "main" java.lang.UnsatisfiedLinkError: xx
at bbb.xx(Native Method)
at aaa.main(aaa.java:9)
What should I do?

1) Use the method name javah suggests. How should java guess just what you
called your native callback this time around? Of course, you could use
RegisterNatives(), but even that would require a method that is at least
once called by the normal calling convention.

2) Use the method signature javah suggests. C++ does method name mangling
to enable overloaded methods, and one of the prices to pay is that you can
not use wrong signatures anymore
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top