Accessing a dll from classes in different packages

Hello java community,
I am new to Java and especially the jni so your help is greatly appreciated.
I am having trouble accessing a Windows native dll from classes in different packages. I placed the .dll in my ClassPath. I am able to loadLibrary successfully from class X in my 'common' package. However, when I try to access the same .dll from another class Y in package 'notsocommon'. I get an unsatisfied link error. I changed the X.h file to include common in the function definition (eg. Java_common_X_functionName) and I did the same to the Y.h file (Java_notsocommon_Y_functionName). I am able to work with the dll from the X class but not the Y class. I don't know what I am doing wrong. I am very new to Java, so any help is appreciated.
Thank you.

I apologize to everyone for posting this. I figured out my mistake, it was in the dll and not in the java. Also using
javah -jni notsocommon.Y
creates the correct header file.

Similar Messages

  • [svn:fx-trunk] 5140: Removing [ExcludeClass] from classes outside the package.

    Revision: 5140
    Author: [email protected]
    Date: 2009-03-02 12:09:24 -0800 (Mon, 02 Mar 2009)
    Log Message:
    Removing [ExcludeClass] from classes outside the package.
    QE Notes: None.
    Doc Notes: None.
    tests: checkintests
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/layout/HorizontalLayout.as
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/layout/VerticalLayout.as

  • Create Classes In Different Packages With Error-free Importing

    Hello,
    I'd like to create a class which inherits from another class from some other package. So I use "import" keyword to involve the class to build my new class on. However, I hope my new class can be in its own package which is different with one the base class is in. To make it clear, please see the example below:
    There are two folders, with name c08 and c09 respectively, in C:\Java which I created for this case. I set the environment variable as C:\Java. There is no problem. Then I saved file "Inter.java" in C:\Java\c08. It's source code is as below:
    package c08;
    public interface Inter {
         void play ();
         void action ();
    And another "Test.java" is saved in C:\Java\c09. Source code as below:
    package c09;
    import c08.*;
    public class Test {
    protected class PC implements Inter {
              public void play () {
                   System.out.println("Play()");
              public void action () {
                   System.out.println("Action()");
    It was successfully compiled for "Inter.java". But when comes to "Test.java", it failed with error message of something like "Cannot find the interface Inter". I tried some other ways and I didn't get any results.
    I hope to create a class using classes from some other packages while keeping the new one in a different package. How can this be done? (I am currently doing this in J2SE 1.4.01 under Windows XP Home Edition)
    Thank you!
    Best Regards
    Felix

    I copied and pasted your code as well as made c08 and c09 directories. I had no errors compiling. I am using NT, but it appears that your problem is Classpath related. You can try to CD to the C:\Java directory and compile using "javac c09\Test.java" That's the command I used.

  • Same class in different package

    I am facing a design decision, I have a set of classes which defined the values of all variables. However, I realized that I need to prepare
    separate set of these classes for different countries (as they may vary), i.e
    my.package.us
         PriceList.java
    my.package.ca
         PriceList.java
    PriceList.java
    ===============
    Public class PriceList {
    public final static Price directFlightPrice = new Price(13500,2); // where 0 is the decimal places
    public final static Price connectFlightPrice = new Price(11000,2); // where 0 is the decimal places
    I am not sure how I can achieve this, would you guys please help? Thank you!

    Isn't this more what you need? You don't want to create a new class, you should create a new instance of a class.
    class PriceList {
        private Price directFlightPrice;
        private Price connectFlightPrice;
        private String country;
        public PriceList(String country, Price directPrice, Price connectPrice) {
            this.country = country;
            directFlightPrice = directPrice;
            connectFlightPrice = connectPrice;
        ... methods to use pricelist variables
    class PriceListTest {
        public static void main(String[] args) {
            Map<String, PriceList> pricesPerCountry = new HashMap<String, PriceList>();
            // This is where you could load data from file and put it into a PriceList object...
            PriceList plUK = new PriceList("UK", new Price(...), new Price(...));
            PriceList plAu = new PriceList("Australia", new Price(...), new Price(...));
            pricesPerCountry.put(plUK.getCountry(), plUK);
            pricesPerCountry.put(plAu.getCountry(), plAu);
            // Use pricelist UK
            PriceList list = pricesPerCountry.get("UK");
    }

  • Moving Bean-class to different package

    Hi,
    For deployment reasons i need the Bean-class in a different package, seperated from package where the Remote and Home are located. I'm not sure how to do this in VisualAge 3.5p2. Simply moving doesn't work.
    Hope someone can help,
    Maarten

    It sounds a little bit strange. Do you want them in packages with different names, like you have bean-class in com.mycompany.project1.mybeanclasses and have the Remote and Home classes in com.mycompany.project2.myremotehomeclasses? It seems possible if you right-click the class you want to move and select 'move', you can move it to a new package. This will be able to separate them.
    Just curious, I think VAJ is very powerful concerning deploying EJBs already so what kind situation makes you want to separate the bean-class and interfaces?
    PC

  • Moving Model Class to different package

    Hi,
    How can i move the model class to a different package in CE 7.1
    Regards,
    Senthil

    Hi Senthil
    I thinks this should be possible to realize on the file system level.
    - Find the folder where your model as well as the model classes are located.
    - Search for all files (.) that contain the model class name. Typically it'll find (*.wdmodel and *.wdmodellclass). Change manually the package name within/near the found lines.
    But why do you need to change the model class package separately from the model package?
    BR, Siarhei

  • Why does protected access also allow access from classes in same package

    Having been asked the question and found myself unable to answer it, I wonder if anyone can explain the reasoning why protected access implies the default access as well?

    Sure:
    ---------- class A ------
    package pkg;
    public class A
    protected static int _a;
    private int _i;
    public A() { _i = _a++; }
    public String toString() { return "instance "+_i; }
    --------- class B ------
    package pkg;
    public class B
    public B() { A._a = 27; }
    --------- class C -----
    public class C extends pkg.A
    -------- class main ----
    public class main
    public static void main(String[] args)
    pkg.B b1 = new pkg.B();
    pkg.A a1 = new pkg.A();
    pkg.B b2 = new pkg.B();
    C c1 = new C();
    System.out.println("a1 is "+a1);
    System.out.println("c1 is "+c1);
    The above classes are legal and compile and when
    run, the output is:
    a1 is instance 27
    c1 is instance 27
    (Please note, this is just an example of what is allowed and why I'm curious as to the advantages of this permitted behaviour, NOT what I would ever write!)

  • How to access graphic components from classes?

    Hi,
    I am creating a Flex application. In my Main.mxml, I add
    different UI elements, such as panels. I also have a few
    actionscript files. Everything is in the same folder. So my
    question is : how can I access a panel created in Main.mxml from an
    actionscript class ? By accessing the panel, I mean things like
    change its properties, etc. Is it possible to access those in a
    'Flash-like' way, using something like _root.myPanel, or is it only
    possible through passing parameters?

    Well...it pains me to see someone obviously new to programming struggle here...so I'll take this one on:
    Here is the BAD way to do it...but it is basically what you are looking for...to learn GOOD ways to do this, please invest in some programming books and learn about encapsulation, MVC, and other programming/architectural styles...anyways...here is the BAD, but easy way:
    In your SGui class, right after the constructor you have to "declare" your object reference as a class member, so edit your file to make it say:
    public class SGui {
         public JButton addStickButton;Then, edit the line in SGui that says:
    final JButton addStickButton = new JButton();so that it just says:
    addStickButton = new JButton();Then, in your Soft class, you can access it just the way you wanted to in your comment:
    gui.addStickButton.setEnabled(false);Other Java programmers reading this thread will probably shoot me for showing you how to do it this way, because it violates principles of encapsulation...but go ahead and use it so you can move forward...but study a little more online or in books to get the hang of it :)
    Message was edited by:
    beauanderson
    Message was edited by:
    beauanderson

  • UnsatisfiedLinkError - Trying to access a DLL from Java

    I am trying to use the Java Native Interface (JNI) to run some C++ code from Java. I tried a simple test program to teach myself that, and it worked perfectly. However, now that I'm tackling a bigger project (A data acquisition program), I get an UnsatisfiedLinkError in the line that calls the function from the DLL.
    Here is the stacktrace: Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.Invoca
    tionTargetException
            at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAc
    tion.java:859)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(App
    licationAction.java:665)
            at org.jdesktop.application.ApplicationAction.actionPerformed(Applicatio
    nAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(App
    licationAction.java:662)
            ... 26 more
    Caused by: java.lang.UnsatisfiedLinkError: fileiotest.dllinterface.startget()V
            at fileiotest.dllinterface.startget(Native Method)
            at fileiotest.dllinterface.start_daq(dllinterface.java:26)
            at fileiotest.FileIOTestView.startrun(FileIOTestView.java:680)
            ... 31 moreI have made sure that the DLL is in the classpath, using both the -classpath tag and by setting the PATH variable. Is something wrong with my DLL itself, perhaps?

    Yes, I have.
    I didn't include the code yet because I thought if someone had similar trouble, there might be something obvious I am overlooking and they wouldn't even need to see the code. I can provide it, however.
    This is the C++ DLL
    // consoledaq.cpp : Defines the entry point for the console application.
    #include <windows.h>                    /* Compiler's include files's */
    #include <string.h>                  
    #include <stdio.h>
    #include "cbw.h"
    #include "stdafx.h"
    #include "dllinterface.h"
    #include "jni.h" //can copy or give full path
    #include <math.h>
    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
        return TRUE;
    #define BOARD_NUM      0                /* Number of A/D board as defined with InstaCal */
    #define BUF_SIZE       10048            /* Size of buffer */
    #define NUM_SECS       10                /* Number of secs to collect data */
    #define ADRANGE        BIP5VOLTS        /* A/D voltage range */
    #define TIMER_NUM      1                /* Windows timer used by this program */
    static HGLOBAL  MemHandle32;       
    /* Variables for AinScan */
    static unsigned short *ADValues;    /* Win32 pointer to A/D buffer */
    static HGLOBAL   ADMemHandle;
    static short     ADCurStatus;       /* Current status for D/A scan */
    static long      ADCurCount;        /* Current count for A/D scan  */
    static long      ADCurIndex;        /* Current index for A/D scan  */
    int              ADOptions;
    long       Count, Rate;
    float      Voltage, Voltage2;
    unsigned short CurValue, CurValue2;
    JNIEXPORT void JNICALL
    Java_daq_startget(JNIEnv *env, jobject obj)
         cbErrHandling (PRINTALL, STOPALL);  /* Set library's error handling */
         ADCurStatus = RUNNING;
         ADCurIndex = 0l;
         ADCurCount = 0l;
         /* Allocate A/D Windows buffer */
         ADMemHandle = cbWinBufAlloc ((long)BUF_SIZE);
         /* Allocate a local WIN32 buffer to hold A/D Data */
         MemHandle32 = GlobalAlloc(GMEM_FIXED | GMEM_DDESHARE, BUF_SIZE *sizeof(short));
         /* Get a 32-bit pointer to the A/D WIN32 buffer */
         ADValues = (unsigned short *)GlobalLock(MemHandle32);
         /* Start up background A/D scan */
         Count = BUF_SIZE;
         Rate = BUF_SIZE / (NUM_SECS * 2);
         ADOptions = BACKGROUND | CONTINUOUS;
         cbAInScan (BOARD_NUM, 0, 1, Count, &Rate, ADRANGE, ADMemHandle, ADOptions);
    JNIEXPORT void JNICALL
    Java_daq_stopget(JNIEnv *env, jobject obj)
         cbStopBackground(BOARD_NUM, AIFUNCTION);  /* Stop A/D subsystem background scan */
         if (ADMemHandle)                 
              cbWinBufFree (ADMemHandle);   /* Free allocated memory */
         if (MemHandle32)
              GlobalFree (MemHandle32);
    JNIEXPORT jfloatArray JNICALL
    Java_daq_getpoint(JNIEnv *env, jobject obj)
         jfloatArray theArray;
         if (ADCurIndex >= 0)
              /* Copy Data from memory to 32 bit memory buffer */
              cbWinBufToArray(ADMemHandle, &ADValues[ADCurIndex], ADCurIndex ,2);
              CurValue = ADValues[ADCurIndex];
              CurValue2 = ADValues[(ADCurIndex + 1)];
         else
              CurValue = 0;
              CurValue2 = 0;
         jfloat tmp[2];
         theArray =  env->NewFloatArray(2);
         cbToEngUnits(BOARD_NUM,ADRANGE,CurValue,&Voltage);                      
         cbToEngUnits(BOARD_NUM,ADRANGE,CurValue2,&Voltage2);
         tmp[0] = Voltage;
         tmp[1] = Voltage2;
         env->SetFloatArrayRegion(theArray, 0, 2, tmp);
         return theArray;
    }And this is the Java class:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package fileiotest;
    * @author Owner
    public class dllinterface {
        public native void startget();
        public native float[] getpoint();
        public native void stopget();
        static {
         System.loadLibrary("daqdll");//This is firstJNI.DLL
         /*if generated by borland
         System.loadLibrary("firstjni");//This is firstjni.dll
        public static void start_daq()
            dllinterface DI=new dllinterface();
            DI.startget();
        public static void stop_daq()
            dllinterface DI=new dllinterface();
            DI.stopget();
        public static float[] get_data_point()
          dllinterface DI=new dllinterface();
          float newtempfloat[];
          newtempfloat = DI.getpoint();
          return newtempfloat;
    }

  • Accessing parent function from class

    Hey guys
    I have a .fla file with some code in the actions panel.
    A bit of code calls a function in a class from the actions panel
    The function in the class is run, but I want to be able to call a function in the main actions panel code from the function in that class
    The class doesn't extend anything so (parent as MovieClip).function() does not work
    Any ideas?
    Thanks
    Chris

    if you're trying to reference code attached to a timeline, your class will need a displayobject reference.  you can pass it a reference when instantiating a class object:
    // on a timeline:
    var c:YourClass=new YourClass(this);  // code your constructor to accept this movieclip reference.
    you can then use that reference to access code in any timeline (that exists when trying to reference):
    private var tl:MovieClip;  // import the mc class.
    public funciton YourClass(mc:MovieClip){
    tl=mc;

  • Same class name, different packages

    Let's say I have two classes called Team, and each are in their own package. I go to import a.Team and b.Team, what do I have to do to make this work?

    Import them both if you need them both. When you go to use them, refer to them by their fully qualified name.a.Team aTeam = new a.Team();
    bTeam bTeam = new b.Team();You don't really need the import statements from a programatic point of view, but it helps make your code more legible to other developers.

  • Import Method From .Class in A Package

    Hello!
    I have a package name
    com.vibesoft.bots.;*
    With a .class file name print in it and a method name print within that .class that prints text to the command line. The print.class file looks like this:
    package com.vibesoft.bots;
    public class print{
    public static void print(String text){
    System.out.println(text);
    //Call this method with: print.print("What_You_Want_To_Print");When I write a script to call the method like so:
    import com.vibesoft.bots.*;
    public class printit {
    public static void main(String[] args) {
    //Here i'm trying to write print("Text"); , but I'm required to write print.print("Text");
    }I can't just write print("Text"), i need to write print.print("Text")
    Is their anyway I can fix this problem?
    Edited by: Speedster239 on Sep 23, 2007 9:35 PM

    Speedster239 wrote:
    It makes a difference because these classes are part of a scriptable program to control the mouse, keyboard, to search the screen for color and so forth.And they do the scripting using Java? Why not use one of the scripting languages.
    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

  • Accessing Field Help from item on different Page

    I manually created a tabular form used for posting and I wanted to implement the field help for the column headers. I have a seperate maintenance form that already has the appropriate help text stored for each item. I want to have my tabular form popup help get the help text from the other form. I looked at the code from the other form and it was doing this for the field:
    javascript:popupFieldHelp('25020711860698767','439667227918056')
    So I went into the Report attributes section of my tabular form and entered this:
    <a href = "javascript:popupFieldHelp('25020711860698767','439667227918056')"> Security Type </a>
    It seems to work perfectly, but I just want to make sure this is the best way to do this. Are the arguments sent to popupFieldHelp unique for every item in an application?

    Sorry. Had to change the href so you could see what I typed:
    <-a href = "javascript:popupFieldHelp('25020711860698767','439667227918056')">Security Type<-/a>

  • Accessing custom dll from Servlet

    Hello,
    I am trying to load a custom dll in iWS4.1SP9 but I seem no able to find the dll.
    Where do I have to place it on the system? I have placed it in WinNt/system32 dir but still could not find it.
    I was sucessful in loading the dll when running as a stand-alone app. What is the difference?
    Thanks,
    Nuri

    Hi !
    In your code i think there is a simple mistake in creating the IntialContext
    for example:
    public Context getInitialContext() throws NamingException
              try{
                   System.out.println("url received here is "+url);
                   Hashtable ht= new Hashtable();
                   ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
                   ht.put("java.naming.provider.url", url);
                   //return new InitialContext(hashtable);
                   return new InitialContext(ht);
              catch(NamingException namingexception)
                   Debug.log("We were unable to get a connection to the WebLogic server at " + url);
    Debug.log("Please make sure that the server is running.");
    return null;
    This intial context is dependent on Application Servers,where exactly placing your EJB's.
    In general....
    Properties prop=System.getProperties();
    prop.put....
    IntialContext context=new IntialContext(prop);
    Like this it should be....
    I hope this will solve your problem,

  • Command Line Compilation of  a Project with different packages

    Hi,
    I am trying to compile a project through command line, which has different packages with many classes in it. Now If I try to compile package by package It's complaining about other referenced classes of different packages. So I created .bat file, which includes all the packages, but it's complaining input line is too long.
    D:\jdk1.3.1\bin>app.bat
    My bat file is
    javac -d d:\Application\build d:\Application\source\com\ibc\rules\login\*.java d:\Application\source\com\ibc\rules\lookup\*.java .................d:\Application\source\com\ibc\wid\events\*.java d:\Application\source\com\ibc\wid\frames\cust\*.java ...
    and so on............
    Is there any solution for this problem?
    Thanks in advance....

    I think the prefered and more elegant way to compile project including packages should be writing makefiles including their compilation, installation, deploying - rules ..
    Make is really powerful, the maybe only weak-point is that there are some distribution of them, gnu-make, microsoft nmake .. which are slightly different, that made porting among platforms difficult.
    The jakarta-ant was a new approach to this which uses xml parser to proof the dependencies, etc ..
    Because I'm not familiar yet with xml & ant and as a in-blooded unix user, "make" is still my prefered way to do roject.
    The easiest way to get unix environment required for using make in Windows platforms is to download the "unxutils". It includes make, bzip2, diff, ... and other unix-tools. Refer to this (found from search by google) :
    http://www.weihenstephan.de/~syring/win32/
    http://www.weihenstephan.de/~syring/win32/UnxUtils.zip
    http://sourceforge.net/projects/unxutils/
    For more documentation on how to write makefile, use make -tool, see
    http://www.gnu.org/manual/
    http://www.gnu.org/manual/make-3.79.1/html_mono/make.html

Maybe you are looking for

  • How can I solve the "could not sign in iTunes Store: An unknown error has occurred." problem

    after finishing watching a movie (paid movie), I tried renting another one but the "Could not sign in " error stopped me from doing that.  I have restarted the Apple TV many times, turned it off, restarted my cable modem, and much more. However, I am

  • How to change remote_login_passwordfile from exclusive to NONE?

    Hi all, I used dbca to create a database in linux server. then created an ops$oracle user using the below SQL: create user ops$oracle identified by externally; grant dba to ops$oracle; How can i change this parameter to NONE? Thanks

  • ITunes stuck with White on Gray Background

    I need help with iTunes please.  Since I installed Lion, my iTunes switched to white on gray background, and its so hard seeing my lists on the sidebar.  I've tried going under the preferences and choosing "dark" but that doesn't do a thing.  Once I

  • ADF 11g: Client Interface method not 'visible' in create of Action Binding

    Hello! I have a simple AM method that I have exposed through client interface. Now I am trying to create action binding in one of the PageDef files so that I can execute some code before the page renders. This worked fine in JDEV 10g. However, for so

  • Reg:Additive Cost

    Hi, For Standard Cost Estimate i want to post freight expenses through additive cost for wat is the Item category we need to take for that and wat the parameters we need to select