Help using native methods

Discussion in 'Java' started by smita b via JavaKB.com, Jul 20, 2005.

  1. 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.aspx/java-general/200507/1
    smita b via JavaKB.com, Jul 20, 2005
    #1
    1. Advertising

  2. 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"
    Stefan Schulz, Jul 20, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Duke
    Replies:
    1
    Views:
    6,187
    Gordon Beaton
    Jun 30, 2003
  2. BARBARA

    native methods from java

    BARBARA, Oct 7, 2003, in forum: Java
    Replies:
    1
    Views:
    396
    Gordon Beaton
    Oct 7, 2003
  3. HappyHippy
    Replies:
    3
    Views:
    329
    Gordon Beaton
    Sep 7, 2006
  4. TastyWheat

    Accessing Native Methods

    TastyWheat, Feb 24, 2007, in forum: Java
    Replies:
    0
    Views:
    303
    TastyWheat
    Feb 24, 2007
  5. Kenneth McDonald
    Replies:
    5
    Views:
    313
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page