Calling functions in dll

Dear all,
I'm facing an issue when a java program (ProgA) calls some functions in a dll, it works fine. But when I use another java program (ProgB) to call the method in ProgA that is calling the functions in dll, it prompts errors (please find the error message at the bottom of this mail). The following scripts are my programs. Please advise.
Can anyone experience the same situation? Please advise how to cope with external library? Should I miss any configuration?
Thanks in advance.
Clive
(ProgA)
package abc.web;
public class Sec_2 {
     // static constructor
     static {
          System.loadLibrary("des");
     public static native int DES_a(String lpszKey, int nMode);
     private static native int DES_b(String s1, String s2, int nAction, int lpnReturnSize);
     private static native void DES_c();
     public int enc2 (String lpszKey, int nMode,String encrypted_msg, int nAction, int lpnReturnSize) {
          int rtn_code = 0;
          rtn_code = DES_a(lpszKey, nMode);
          rtn_code = DES_b(e_msg, OutputMessage, nAction, lpnReturnSize);
          System.out.println("Encrypted string (inside) is "+ OutputMessage +" with return code "+rtn_code);
          DES_c();
          return lpnReturnSize;
     private static String OutputMessage;
     public void setOutputMessage(String s) {
          OutputMessage = s;
     public static String getOutputMessage() {
          return OutputMessage;
     public static void main(String [] argv) {
          int return_code = 0;
          int crypt_return_size = 0;
          enc2(s1, i1, s2, i2, i3);
(ProgB)
package xyz.pen;
import abc.web.Sec_2;
public class LoginOn extends JDialog{
     public CreateLoginDialog() {
          Sec_2 ddd = new Sec_2();
          Sec_2.enc2(a, b, c, d, e);
          System.out.println("Message "+ Sec_2.getOutputMessage());
library des.dll contains function DES_1, DES_2, and DES_3 with following definitions.
JNIEXPORT jint JNICALL Java_abc_web_Sec2_DES_1a(JNIEnv *, jclass, jstring, jint);
JNIEXPORT jint JNICALL Java_abc_web_Sec2_DES_1b(JNIEnv *, jclass, jstring, jstring, jint, jint);
JNIEXPORT void JNICALL Java_abc_web_Sec2_DES_1c(JNIEnv *, jclass);
If Sec_2.class is run solely, the program shows the result normally.
However, if we run LoginOn.class, the following error messages display.
ERROR MESSAGE
E:\>java xyz/pen/LoginOn
Exception in thread "main" java.lang.UnsatisfiedLinkError: DES_a
at xyz.pen.LoginOn.DES_a(Native Method)
at xyz.pen.LoginOn.<init>(LoginOn.java:247)

Hi
Make sure that the dll is visible to LoginOn
You can do so by adding the DLL directory to the Java runtime library path, i.e. pass -Djava.library.path=<dll dir>(alternatively, copy the DLL to Java program's working directory). If the Java code can't find the library, you will get a java.lang.UnsatisfiedLinkError
Hope this helps.

Similar Messages

  • Runtime can't be found when calling function in DLL

    Hi
    I compiled VIs in LabVIEW 6.0i to be DLL file and used it in VB. I used it smoothly until I installed LabVIEW 6.1. When I run my VB application which called that DLL, I got error that is "DDT_Cmd requires a version 6.0 (or compatible) LabVIEW Run-Time Engine." How can I solve this problem?

    Yes, you can have many different versions of the LabVIEW Run-Time Engine installed at once. We average 3 - 4 concurrent versions of LabVIEW on our machines for support.
    Randy Hoskin
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • How to auto-recognize the function parameters called from a DLL built by VC6.0

    Hi,
    I use Teststand 3.5 with C/C++ Adapter, and the DLL is built by VC6.0.
    While I specify module for an action, the parameters of a function called from the DLL are not recognized.
    Since I have the DLL source, I know I can select the source file and verify prototype in the "Source Code" Tab.
    Under the way, almost parameters can be recognized, but some parameters, e.g. HANDLE or I definded, can not ( shows error message "The function definition cannot be found in the source file...").
    How to recognise these parameters?
    Thanks.

    The problem isn't that TestStand doesn't have enough native types. A handle can be represented in a TestStand numeric variable just fine. Instead, the issue is that when you select Verify Prototype, TestStand doesn't fully pre process your headers and compile your code to determine the types. To do so would require TestStand not only to be a full C/C++ compiler but it would also have to be able to read your compiler's projects and settings to resolve include paths, macros, etc.
    Since TestStand is not a C/C++ compiler, it just looks for the standard basic data types plus a few more that are common in test code.  Other data types will not be automatically recognized even if they can be mapped to TestStand types.
    Another option it to create a type library for your dll so that TestStand can automatically read the data type information from it. However, I don't know if that works for struct parameters and I looked for the document on devzone that explains how to do that in VC++ and it has been moved or deleted
    Maybe an AE would know of a link to a current document that describes how to do this?

  • Simulation model which call functions in an other dll...

    I have a C simulation model that I implement like NI Model Framework template (NI_VStand_Model_Framework_Guide.pdf ). If I use this simple model I can deploy on my PXI. But I must call functions which are in an other dll. When I call functions in other DLL I can't deploy because Veristand specify that the model is not compatible.
    NI VeriStand: The specified compiled model is not compatible with NI VeriStand.
    =========================
    NI VeriStand: NI VeriStand Engine.lvlib:VeriStand Engine Wrapper (RT).vi >> NI VeriStand Engine.lvlib:VeriStand Engine.vi >> NI VeriStand Engine.lvlib:VeriStand Engine State Machine.vi >> Model Execution.lvlib:Initialize Model Loop Data.vi >> SIT Model API.lvlib:Initialize Model.vi >> SIT Model API.lvlib:Load Model DLL.vi
    <append>=========================
    NI VeriStand: Failed to load c:\ni-rt\NIVeriStand\Models\LD1_T1.dll
    If I use DLL Checker there is no bad import.  How to add a simulation model in veristand which call function in an other DLL?

    Thank you for your answer.
    I know how to import a dll in veristand. My Dll  is LD1_T1. I can import it in Veristand without error. But this DLL depends of an other dll (addition.dll) as you can see in the print screen.
    When I try to deploy to my PXI I have an error message of compatibility. 
    NI VeriStand: The specified compiled model is not compatible with NI VeriStand.
    =========================
    NI VeriStand: NI VeriStand Engine.lvlib:VeriStand Engine Wrapper (RT).vi >> NI VeriStand Engine.lvlib:VeriStand Engine.vi >> NI VeriStand Engine.lvlib:VeriStand Engine State Machine.vi >> Model Execution.lvlib:Initialize Model Loop Data.vi >> SIT Model API.lvlib:Initialize Model.vi >> SIT Model API.lvlib:Load Model DLL.vi
    <append>=========================
    NI VeriStand: Failed to load c:\ni-rt\NIVeriStand\Models\LD1_T1.dll
    For LD1_T1.dll I have use NI Model Framework template (NI_VStand_Model_Framework_Guide.pdf ).
    If I check my Dll with dll checker it's ok but I can't deploy. 
    Please somebody have an idee to deploy my model ?

  • Call function in LabView from a DLL, then access global variable from DLL

    I have created a DLL in LabWindows with a function and a structure.  I want to call the function from within LabView and then access the global structure.  I am able to call the function from the DLL with a "Call Library Function Node" and can access the return value, but I cannot figure out how to access the global structure.  The structure is declared in the DLL header file with __declspec(dllimport) struct parameters.
    Is there any way of accessing this structure without using the Network Variable Library?
    Solved!
    Go to Solution.

    dblok wrote:
    When you say "access to" or "the address of" the global variable, do you mean to pass the variable as an argument to the function call in the DLL?  If so, then I was not really sure how to pass a cluster from LabView by using the "Call Library Function Node".
    Yes, that's exactly right.  I would include a pair of helper functions in the DLL to read and write the global variable.  Alternatively you might write separate helper functions for each field inside the global structure, depending on the number of fields and whether you want to do any validation on the values.
    You can pass a cluster by reference to a function that expects a struct by setting the parameter to Adapt to Type, so long as the cluster does not contain any variable-length elements (strings or arrays).  The cluster needs to match the struct exactly, and sometimes that involves adding extra padding bytes to make the alignment work.  Variable-length elements in LabVIEW need to be converted to clusters containing the same number of elements as the struct definition (for example, if your struct contains char name[12], you would create a cluster of 8 U8 values, and you could use String to Array of Bytes followed by Array to Cluster to convert a LabVIEW string into that format).  If the struct contains pointers it gets more complicated, and it may be easier to write functions in the DLL to access those specific elements individually.
    If you can't get this working or need help, post your code and an explanation of the error or problem you're seeing.
    EDIT: it is also possible to include a single function in the DLL that returns the address of the global variable, which LabVIEW can then use to access and modify the data, but that's more complicated and likely to lead to crashes if you don't get the memory addressing exactly right.

  • How to call functions defined and packed in a .dll file

    hi,
    my client have provided me with a .dll file which implements all functions tasks.
    earlier we created a applications in vb that accessed functions from the .dll file provided by client.
    now he wants java implementation of the same application written in vb.
    now how to access functions in .dll file provided by the client from java source code.
    regards,
    s.mohamed asif

    For this you should write JNI wrappers for the native functions, that is you create class with the native function prototypes as native methods, implement these methods with native functions in JNI module, each JNI function calls a native function from your DLL.
    I know that JNI coding is a greate pain. That is why I am developing Java Platform Invoke which is a paradigm of .NET Platform Invoke. See my demo at
    http://www.sharewareplaza.com/Java-Platform-Invoke-API-Demo-version-download_49212.html

  • How to access Call Back Functions using *.dll in the Labview?

    Hai,
    I am Pavan Ram Kumar Somu.
    I am new to Labview, currently I am working on MVB Interface.
    I need to access the API functions from *.dll file in Labview, as of now , I am doing this with Call function Library node in Labview but it does not support the following data types like
        1. Pointer Arguments(To which memory it points in Labview)
        2. function pointers Arguments
        3 .pointers in structures and pointer structures in structures and many other data types.
    Please Answer the below queries also:
    1. How to pass pointer arguments to API functions in DLL and how to collect pointer  
        return types from API functions in DLL
    2. How to pass structure arguments to API functions in DLL and how to collect structure
        return types from API functions in DLL
    3. How to use callback functions(nothing but function pointers) in Labview and how to
        collect callback fuctions return types from API functions in DLL
    I need your help while passing these datatypes to API functions in DLL from labview.
    Suggest me if there is any other alternative for implementing this task.
    I am referencing some examples here:
    Examples:
    I)
    Unsigned short int gf_open_device(void *p_device_config, unsigned long int client_life_sign_timeout, unsigned short int *device_error)
    void *p_device_config: How to access/pass these arguments in LabView and to which memory location it points in LabView.
    II) #include <windows.h>
         #include <process.h>
         HANDLE rcvEvent0, rcvEvent1;
    /* Function call*/
    CanGetReceiveEvent(handle[0], &rcvEvent0);
    Above is a piece of C code, Now I want to use HANDLE datatype which is windows based, how to use these type in the LABVIEW.
    With regards
    Pavan Ramu Samu

    "Somu" <[email protected]> wrote in message news:[email protected]...
    Hai,
    I am Pavan Ram Kumar Somu.
    &nbsp;
    I am new to Labview, currently I am working on MVB Interface.
    &nbsp;
    I need to access the API functions from *.dll file in Labview, as of now , I am doing this with Call function Library node in Labview but it does not support the following data types like
    &nbsp;&nbsp;&nbsp; 1. Pointer Arguments(To which memory it points in Labview)
    &nbsp;&nbsp;&nbsp; 2. function pointers Arguments
    &nbsp;&nbsp;&nbsp; 3 .pointers in structures and pointer structures in structures and many other data types.
    &nbsp;
    Please Answer the below queries also:
    &nbsp;
    1. How to pass pointer arguments to API functions in DLL and how to collect pointer&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp; return types from API functions in DLL
    &nbsp;
    2. How to pass structure arguments to API functions in DLL and how to collect structure
    &nbsp;&nbsp;&nbsp; return types from API functions in DLL
    &nbsp;
    3. How to use callback functions(nothing but function pointers) in Labview and how to
    &nbsp;&nbsp;&nbsp; collect callback fuctions return types from API functions in DLL
    &nbsp;
    I need your help while passing these datatypes to API functions in DLL from labview.
    &nbsp;
    Suggest me if there is any other alternative for implementing this task.
    &nbsp;
    &nbsp;
    I am referencing some examples here:
    Examples:
    I)
    Unsigned short int gf_open_device(void *p_device_config, unsigned long int client_life_sign_timeout, unsigned short int *device_error)
    &nbsp;
    void *p_device_config: How to access/pass these arguments in LabView and to which memory location it points in LabView.
    &nbsp;
    II) #include &lt;windows.h&gt;
    &nbsp;&nbsp;&nbsp;&nbsp; #include &lt;process.h&gt;
    &nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp; HANDLE rcvEvent0, rcvEvent1;
    &nbsp;
    /* Function call*/
    CanGetReceiveEvent(handle[0], &amp;rcvEvent0);
    &nbsp;
    Above is a piece of C code, Now I want to use HANDLE datatype which is windows based, how to use these type in the LABVIEW.
    &nbsp;
    With regardsPavan Ramu Samu
    Search the forum (forums.ni.com) for callback, pointer or handle, and you'll find that it is all possible, but not very easy.
    e.g.: http://forums.ni.com/ni/board/message?board.id=170&message.id=88974&requireLogin=False
    Regards,
    Wiebe.

  • CVI crashes when calling function from external DLL

    I'm calling a CVI library from Test Stand 4.1.  In that CVI library I load an external DLL (using LoadLibrary) and create a few function pointers (using GetProcAddress).  The DLL loads successfully, and I get addresses for all of the imported functions.  
    However, when I one of the functions is called CVI crashes (Test Stand says it lost the ActiveX connection to CVI) when executing in an external CVI instance.  If executed in the Test Stand process I get a system level exception.
    If I step through the code in CVI, it hangs after trying to step into or over the call to the function pointer from the external DLL.
    I am able to call the functions in a small test project I created in CVI, however when integrating it into an existing test library and calling it through Test Stand it fails.
    Any ideas on how to go about debugging this issue?

    Have you tried calling into the dll that CVI calls directly from TestStand?  I am curious to know if this also crashes.
    I am also curious to know if there are any path references in the dll that is called by the CVI program.  If so are they relative, or absolute paths?
    I ask because one of the possibilities is that relative paths are being used to specify a path from the location of the code that is called, and they are not working because the current working directory is being specified by TestStand, and the paths are not relative to the working directory given by TestStand.
    Jensen
    National Instruments
    Applications Engineer

  • Call function from C++ (dll file) in Flex

    Hi,
    i using Adobe Flash Builder with Flex 4 , i write a C++ Code in dll File , i need to access to my Function in dll file in Flex ?? what should i do ??

    Lets make sure you are performing the correct actions:
    1.  Place a Call Library Function node on your block diagram.
    2.  Double click the node to open up the Call Library Function dialog box.
    3.  Click the Browse button and navigate to the DLL function.  Select the proper DLL and click Open, or just double click on DLL.
    4.  On the Function Name box, click on down arrow.  A list of functions found in the DLL should be displayed.  Choose the function.
    5.  On the Calling Conventions box, click on down arrow and select C or WINAPI.  In your case, it should probably be C.
    6.  The Parameter box should show return type.  In the Type box, select the data type of the return value.  Since you won't see HRESULT here, you need to find out what data type HRESULT is in the C code.  I would guess it is a numeric so select numeric from the drop down list.
    7.  Click the Add a Parameter After button.
    8.  In the Parameter box, change the name arg1 to the actual name of your first parameter, which is byPortNumber.
    9.  In the Type box, choose Numeric, since a BYTE is a numeric in Labview.
    10. In the Data Type box, choose Unsigned 8-bit Integer, since a BYTE is a U8 in Labview.
    11. In the Pass box, choose Value.  If the C parameter was a pointer (*BYTE), you would choose Pointer to Value.
    12. Verify that the contents of the Function Prototype box contains the correct syntax according to the C declaration.
             C:  HRESULT RSPInitComm (BYTE byPortNumber)   should be in Labview: long RSPInitComm(Unsigned char byPortNumber)
    13. Click OK button.
    Try it out.
    If you get a crash, change the Calling Convention to WINAPI.
    - tbob
    Inventor of the WORM Global

  • "Calling functions that are in a class based DLL (MFC extention DLL)"

    "Calling functions that are in a class based DLL (MFC extention DLL)"
    "Calling functions that are in a class based DLL (MFC extention DLL)
    I have a DLL written in VC++ using MFC exteintion DLL.
    The functions are used to extract information from a hardware card.
    eg.:
    class AFX_EXT_CLASS WSDevice : public cAsyncSocket
    This is a class in a DLL. There are a number of functions in this DLL that we need to call from Labview 5.0
    How do we call these functions?
    Normally (in VC++ /C++) we ceate a instance of this class like WSDeviceObj and use the function call :
    WSDeviceObj.fucntion name
    Kindly Help.
    Satish Narayana"

    You can create a wrapper dll from which you can call your dlls functions.
    Guidelines on how to create a dll that can communicate with LabVIEW are provided in the document "Using External Code in LabVIEW", which should be included with LabVIEW. You can download the document also from www.ni.com at:
    http://digital.ni.com/manuals.nsf/web_productcurre​nt/4F1447F7CD83D6D88625690D00637CED?OpenDocument
    Regards;
    Vargas
    www.vartortech.com

  • Call function from "CP210xManufacturing.dll"- Silicon Labs

    I am developing a production line test system that includes retrieving and setting the VID, PID, product string, serial number maximum power consumption of a Silicon Labs CP2102 USB - UART bridge using Labview 8.2.
    Unfortunately I could only call one function { CP210x_GetNumbDevices() }. Wondering any one can help me to call others.
    The Document  : http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an144.pdf
    CP210xManufacturing.dll :http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/Interface/en/an14...
    Tuong

    G'day Tuong,
    I'm having issues finding the device i want (VID / PID) on my machine using the "CP210xManufacturing.dl"and calling function "CP210x_GetNumDevices()"...
    Just wondering if you have any details on this....
    Hahaha, I just saw the date you wrote this thread... Hmmm, I might just ask you at work tomoz...
    Cheers
    Tim

  • How can I build an application that calls functions in a dll if the associated hardware is not present?

    I am trying to build an application that use the "Call Library Function" node to call functions in a dll.
    The dll was provided by a third-party and includes functions to drive an I2C communication board.
    The problem I have is that the dll does not not properly because the hardware is not present.
    Therefore when I load the VI a broken arrow is displayed and when I am not able to build the application.
    I will not be running the application on the PC where I build the application, therefore I want to be able to build the application on a remote PC that has not all the hardware installed. Once the application will be build it will be installed on the target PC that has all the hardware.
    How can I make the application builder to build the application event if the dll is not properly loaded? (the dll will be properly loaded on the target PC)
    I want to do this on LabView 5.1.1, any ideas?

    Some .dlls don't try to attach to the driver when loaded.
    I've worked with both and unfortuately, I've not figured out a way around this problem.
    You could possibly use the Conditional Disable structure around the dll calls so they would not be loaded unless you're in the runtime engine. But i've not tried this so I don't know for sure if it's possible.
    Anyone??
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Calling Window's Dll Functions from Java

    Hello Audience,
    Is there a way to call Win32/64 based Dynamic-Link-Library functions from Java?
    Thanks,
    GenKabuki

    Yes.
    In general, if you are trying to call functions in an existing dll, you will have to write a "wrapper" dll that meets the java jni interface requires. There are tools around wich purport to generate these for you. Do a google serach; among other tools, you should turn up JACE.

  • Call function RFC in a loop and kill old session

    Hi,
    we have a problem with a program.
    here's a part of the code:
    DO.
        CALL FUNCTION 'YC_REFRESH_GPT_START_CM25' STARTING NEW TASK 'TEST'
          EXPORTING
            i_profile       = p_prfl
            i_werks         = p_werks
            i_arbpl_low     = s_arbpl-low
            i_arbpl_high    = s_arbpl-high
          TABLES                                              
            t_arbpl =  it_arbpl.                                
        PERFORM wait_for_refresh.
        PERFORM terminate_session.
      ENDDO.
    So the program does a call function, waits a while, then terminates the session and recalls the function.
    Apparently, like this the data should be updated.
    But in the terminate session, the session is terminated using:
    CALL 'ThUsrInfo' ID 'OPCODE'  FIELD opcode_delete_mode
                       ID 'MODE'    FIELD l_mode.
    And it works the first time, but the second time there is a dump.
    So, is there another way to achieve what this program is trying to do?
    Or is there another way to kill the session?
    Thanks!!

    Hi,
    the DLL will stay in memory as long as there is a program running which has not closed (unloaded) the DLL.
    Doing repetitive calls to the DLL is irrelevant in this context. LV opens the DLL as soon as needed and will only unload it when there is no VI in memory which has a CLN to that DLL...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Passing structures bet top level functions and DLL's

    I need to access information stored in a structure(manipulated within a DLL)
    from
    the calling function. I defined the structure in the DLL include file and
    #include "dll_include.h"
    in the source code. The dll function manulipates the contents of the structure
    as desired; however,
    I can not get access to that structure from the calling function. If anyone
    has any ideas, I would
    certainly appreciate the help
    Phil

    Hi Phil
    I think the key for this problem is simply to export that structure in the
    dll that you want to access from the other app.
    for example if you write in your dll_include.h file something like this:
    typedef struct
    ULONG ID;
    CHAR Name[32];
    } MY_APP_PERSON,*P_MY_APP_PERSON;
    typedef void (*SET_PERSON)(void);
    then in your dll source write:
    #include "dll_include.h"
    DLLEXPORT MY_APP_PERSON DllPerson;
    DLLEXPORT void SetPerson()
    DllPerson.ID = 3;
    lstrcpy(DllPerson,"Daniel A.B");
    In your other application which uses this dll write:
    #include "dll_include.h"
    static P_MY_APP_PERSON AppPerson;
    static SET_PERSON SetPerson;
    void main()
    HINSTANCE dllHandle;
    dllHandle=LoadLibrary("Persons.dll");
    if(dllHandle)
    AppPerson=(P_MY_APP_PERSON)GetProcAddress(dllHandle,"DllPerson");
    SetPerson=(SET_PERSON)GetProcAddress(dllHandle,"SetPerson");
    // Watch here with the debbuger the AppPerson structure state it
    will probably containt dirty data
    SetPerson();
    // Now watch again the value of AppPerson and see it was changed
    by calling SetPerson
    Phil Spratt wrote in message
    news:[email protected]..
    >
    > I need to access information stored in a structure(manipulated within a
    DLL)
    > from
    > the calling function. I defined the structure in the DLL include file and
    > #include "dll_include.h"
    > in the source code. The dll function manulipates the contents of the
    structure
    > as desired; however,
    > I can not get access to that structure from the calling function. If
    anyone
    > has any ideas, I would
    > certainly appreciate t
    he help
    > Phil

Maybe you are looking for