Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Help using native methods

Reply
Thread Tools

Help using native methods

 
 
smita b via JavaKB.com
Guest
Posts: n/a
 
      07-20-2005

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?


--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200507/1
 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      07-20-2005
On Wed, 20 Jul 2005 05:19:07 +0000, smita b via JavaKB.com wrote:

> 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

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Accessing Native Methods TastyWheat Java 0 02-24-2007 11:38 PM
How to return data through native methods parameters? HappyHippy Java 3 09-07-2006 01:46 PM
native methods from java BARBARA Java 1 10-07-2003 04:55 PM
ArrayList and native methods Duke Java 1 06-30-2003 07:51 AM



Advertisments