JNI: experience in creating DLLs with G++ (mingw32)?

Hello.
I'm trying to create a DLL:
--------------/HelloWorld.cpp/------
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayMessage(JNIEnv *env, jobject obj)
printf("Hello world!\n");
return;
I previously created 'HelloWorld.java'
class HelloWorld
public native void displayMessage();
static
System.loadLibrary("HelloWorldImp");
I created 'HelloWorld.class'.
I created the header file 'HelloWorld.h':
c:> javah -jni HelloWorld
But I do not have any idea to create the DLL.
I tried with:
c:> g++ -I"D:\j2sdk\include" -I"D:\j2sdk\include\win32" HelloWorld.cpp -shared -o HelloWorldImp.dll
But I get this error message when calling from 'Main.java':
Exception in thread "main" java.lang.UnsatisfiedLinkError: displayMessage
at HelloWorld.displayMessage(Native Method)
at Main.main(Main.java:6)
In order to get this message I created 'Main.java':
class Main
public static void main(String[] args)
HelloWorld hello = new HelloWorld();
hello.displayMessage();
Does anybody have any experience in creating DLLs with G++???
Thank you very much.

Or is it better GCC?

Similar Messages

  • Create dll with arrays and call it

    I am trying to create dll with labview in order to pass a 2d array to the main program. The problem is that I don't really know how to create the function to call it (I don't know much about pointers)
    The function I have created to call the dll is void Untitled1(TD1Hdl *Array1) which is suposse to return the array created on it.
    For example, in the program attached, how should I do to pass the array to another program using dlls?
    Thanks a lot,
    Juanlu
    Attachments:
    Untitled 1.vi ‏7 KB

    The code you've provided doesn't do anything (just a control wired to an indicator) so I'm not sure what you're asking here.
    If I understand correctly, you want to build a DLL from your LabVIEW VI.  From what language will you call that DLL?  There is no standard way to pass a 2-D array.  If you can convert to a 1-D array, you can use a simple pointer.  With a 2-D array, you're stuck with LabVIEW's array representation (the TD1Hdl type), which means that whatever code calls that function will need to understand the LabVIEW data type and how to manipulate it.

  • Cannot create dll with JNI

    hi all,
    i have a c++ coding for a softphone. I opened that file in vc++ and i'm able to create a .exe file from that.
    the .exe file is running fine( it is searching for the server and is getting registered there).
    now i wanted to add jni to it.
    so i have written a java program to one of the methods in the c++ program( void pjstart() ), compiled it and created a header file.
    now i replaced the c++ function with the stuff generated in the header file,( JNIEXPORT void JNICALL Java_test_pjstart(JNIEnv *env, jobject jobj) )
    now i'm unable to build that file in vc++. it is showing some errors..

    You need to start by creating a dll project in VC using a wizard. That should compile, build and you can even load it in java although it won't do anything.
    Then you implement the signatures provided in the h file that you get from javah.

  • Help creating .dll with c using JNI

    Hi. I have created a JNI application that uses C to call Java. Now, I am trying to create the .dll for windows. I am using VS C++ compiler. My program compiles; however, it doesn't seem to start the JVM. I am not sure how to pass the arguments in VS C++ while builiding and running. Please let me know. Thanks.

    Hey,
    Thanks. I apologize for not being clear. I have created the dll file and an application that links to that dll and executes the code. It creates the .exe file and when I execute it, it goes through the sample() function that just prints "Hello", and then it goes through the startJVM() function where the JVM is intended to start; however, the status of JVM is returning -1. It's not able to start JVM. I have included the path for the jvm.dll and jvm.lib. But, still won't work. Please reply with suggestions/comments. Thanks again.

  • How to create dll with visual c++ 6.0

    I have create two file ( file.h, file.cpp)
    I make a new project in visual c++ 6.0, to make dll wizard.
    and then I add code (file.h, file.cpp) in this project. But when i build it has a error.: fatal error C1010: unexpected end of file while looking for precompiled header directive.
    help me...

    Hi,
    For me, when I make the .dll file with Visual C++, I used the cl.exe to do the job. Open the dos command, type cl then see the option, you should soon find out the solution, for futher question, you can email me at [email protected] and I will reply you as soon as possible.
    With my best,
    Zike Huang(jim)

  • Creating Dll with Vision Library

    Greetings Board Members,
    I have a small Application For which i want to make a shared DLL and test them before deploying at other co worker computer, The application uses the Labview Vision, The DLL are made by Building the DLL.
    When I use the same dll and call them with labview i get an error code while the VI Modules with which DLL are made are used instead of DLL they are running OK. Can some one throw light on this issue and how it can be solved. The application is simple, Initialze USB Grabber, Snap and save image, Close Grabber. I am getting Error code in snap and save image.
    Regards
    Harjeet

    1.What is the error number or describtion you get?
    2.Do you know that you will need to have a vision runtime license ($) at the other computers where you want to run the dll?
    Christian

  • How to use a C# dll with JNI

    After a ton of issues, I finally got this working properly. I've come across a lot of forum posts about the various problems and VERY few answers so I thought I would post my solution here.
    To do this, you need to create a managed C++ layer in between C# and java. The JNI functions in C++ dll can make calls to the C# dll directly, and your java program can make calls directly to the native JNI functions. Some important notes on using C# classes in C++ are:
    -gcroot<CSClass ^> should be used on any objects that are instances of some C# class.
    -the symbol ^ should be used with all C# references (its the symbol for references)
    -gcnew should be used to allocate C# objects
    -in visual studio, add the C# dll as a reference rather than using #using <CsDLL.dll>
    -do not use #using <CsDLL.dll>
    The next issue is loading the libraries. By adding the folder your C++ dll is located in to the Djava.library.path VM argument, you can load your C++ library with System.LoadLibrary("Cppdll.dll"). You DO NOT need to load the C# dll in your java program. In fact, it will ignore you if you try. The problem with loading this dll is with how the CLR searches for referenced assemblies. The CLR First searches the DEVPATH environment variable (if the machine.config file has developer mode set to on), then it searches the GAC, then it searches the codebases, then it searchs the current executable's directory along with a list of definable subdirectories (probes).
    DEVPATH is a decent option, but it requires modifying the machine.config file to be in developer mode. Once that is done, it acts just like the PATH environment variable.
    If your C# dlls are strongly named, I would recommend adding them to the GAC or using codebases. However I have not done this and am not sure how.

    Hi,
    i have to use a c# dll in my java program .by following this link http://www.codeproject.com/KB/cross-platform/javacsharp.aspx i done that.but it is working for only one c# program.if i am trying to use a dll it is throwing error
    # An unexpected error has been detected by Java Runtime Environment:
    # Internal Error (0xe0434f4d), pid=3988, tid=3704
    # Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode, sharing windows-x86)
    # Problematic frame:
    # C [kernel32.dll+0x442eb]
    # An error report file with more information is saved as:
    # D:\Work\EclipseWorkspace\HelloInflux\hs_err_pid3988.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    Please help me out. i want a few steps to invoke a c# dll by using jni

  • How to create a dll with strong name

    Hi All,
    For some security purpose, I need to create a dll with strong name by packaging the bean. I am able to create a dll from the bean but how do I create a strong name(sign) dll? I tried using jarsigner utility to sign the jar and then convert it into dll using packager utility but still the resulting dll is not signed. Please anyone let me know how can generate a signed dll by packaging my bean. Any suggestion/help is most welcome. Thanks in advance.

    Good information on strong names:
    http://www.ondotnet.com/pub/a/dotnet/2003/04/28/strongnaming.html
    Step-by-step procedure:
    1. Download Signer from Codeplex. No installation is necessary.
    2. Backup your unsigned assemblies
    3. Open the Visual Studio Command prompt or otherwise make sure that your PATH includes the .NET SDK binaries, and change to the directory where your assemblies are located
    4. In a command window, execute:
    PATH_TO_SIGNER.EXE\signer -k FILENAME OF YOUR KEY -outdir TARGET DIR -a YOUR DLL
    5. The resulting assemblies should now have a valid strong name from your company key. You can check this with:
    sn -T YOUR DLL
    The public key token must match the token of your public key.
    BTW - this is totally unrelated to Java Programming.

  • How create a DLL with module python?

    Hello,
    I am a beginner in TestStand,
    I would like to know, how create a DLL with module Python? because for create a sequence, we must own a DLL.
    Thank you for your answer
    Vincent
    Solved!
    Go to Solution.

    Hello,
    I would like use TestStand with Python module. So I believe, we must use a DLL for execute a test, I'm wrong because I can use .exe for realize a test.
    Now I know how use TestStand with Python module but I have a mistake. I wonder which is error 255?
    Whereas I use .exe in Language C, I have no error.
    Thank you for your anwser.
    Vincent
    Attachments:
    Setup_Test.jpg ‏244 KB
    Report.jpg ‏258 KB

  • Making DLL with C++ builder to use in Labview

      Anybody knows how to make DLL in C++ builder to use in Labview?? 
      Regards,

    smercurio_fc wrote:
    MCFSE wrote:
    This is a good question that does not appear to be addressed in that other thread.
    But is addressed via several NI KnowledgeBase articles and NI Community examples. For example: https://decibel.ni.com/content/docs/DOC-14564
    Well not verbatim, as that document refers to Visual Studio, not C Builder. But creating DLLs in C Builder for use in LabVIEW is no different than creating DLLs in C Builder for any other programming environment that can call unmanaged DLLs. How to configure C Builder to create a DLL, is really beyond the tasks anyone from NI should be required to explain. This requires someone who is familiar with C Builder and requesting a supplier to have specific experience with tool X goes a bit far. NI and most others are using Visual Studio so that is what gets explained. If some C Builder crack would come up with a tutorial targeted at integration with LabVIEW and post that here or someplace else, that would be of course great, but alas, nobody so far has felt the desire to step up to the challenge. There is no inherent difficulty with C Builder created DLLs to be used by LabVIEW, but apparently some difficulty of people to understand how to use C Builder to create working DLLs at all. Similar problems can appear for beginners with Visual Studio and since this is the tool mostly used here around, there are several tutorial style documents available that try to handhold the beginner to get a DLL at all.
    Personally I'm not sure that is ideal either, since those people usually know very little about C programming, or more precise if they know about C programming, they will be able to learn to use the tool in question, with some simple, non LabVIEW oriented examples from elsewhere and then easily apply that knowledge to LabVIEW with the help of the Visual Studio examples posted in quite big numbers, even if they use a different tool than Visual Studio.
    Other even more challenging topics would be to use CygWin, MingW, Bloodshed Dev C++ and similar compilers and write tutorials about them. However the challenges with all of these is to get them even installed well on your development system and to figure out various configuration hassles, also when trying to distribute the result later on.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to access vc dll with java

    I need to access vc dll with java. Now I only have *.h,*.lib, *.dll,no *.cpp,because the dll is from others. I cann't modify the *.cpp files for java. so what should I do .
    Best wishes.

    Create a JNI wrapper for rhe dll:
    1)Create a java class that defines methods that correspond to the methds in the c++ dll
    2)compile this, and compile it with the jni compiler to get the c++ header files.
    3)Create a C++ file that implements the methods defined in the header file, calling the c++ code as necesssary and using the JNI helpess to translate parameters from java form to C++ from.
    4)Perform any initialisation of th c++ dll by adding a DllMain() or equivalent under unix/linux
    5)create a makefile to build a dll from the above, linking to your import (.lib) library
    6)make sure both DLLs are with your java class files when you run the java app.

  • Webi Stucks while trying to create report with BW7.0 (WIS 10901)

    Hello,
    I have some problem about using data created from BW 7.0
    1. After I try to drag more than one object to create report from webi and run the query, it got sutcked and appear error as below;
    A database error occured. The database error text is: The MDX query SELECT {  } ON COLUMNS , HIERARCHIZE( UNION(  { [0GL_ACCOUNT                   INT].[INT                             0HIER_NODE] } , { GENERATE (  { [0GL_ACCOUNT                   INT].[INT                             0HIER_NODE] }  , { Descendants( [0GL_ACCOUNT                   INT].CURRENTMEMBER, [0GL_ACCOUNT                   INT].[LEVEL01]) } ) }  ) )  DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON ROWS FROM [$0ABC_C06] SAP VARIABLES [0DAT] INCLUDING 20080606 failed to execute with the error See RFC trace file or SAP system log for more details. (WIS 10901)
    this error appears when I try to..
    - create query with more than one object
    - enable drill-down for the object and click the report to drill down
    (This error appears the same in Voyager when drag objects into crosstab)
    2. problems with displaying Thai language content created from BW, after I created object, thai content always appears as "######" event I change font to "tahoma", it returns the same result.
    any expert could help me... thanks in advance
    I use BOBJ XI 3.0, SAPBW 7.0
    step:
    1. Create universe connect to BW 7.0 and export universe
    2. logon to infoview, choose universe to create report from webi
    3. drag object and test drill down
    and step for voyager
    1. create voyager connection to SAP BW 7.0 use specified username and password
    2. use voyager to create report
    3. drag object into crosstab

    Hello.
    We have solved this issue. We tested our connection with MDX Parser in transaction SM59 and that resulted in errors. Then we applied SAP note 1032461 to replace an application server dll (librfc32u.dll). After this procedure, the WebIntelligence was able to run queries with more then 2 dimensions and key-figures!
    Thanks for all.

  • How to create dll in Visual Studio 2008 in Visual C++

    Hello,
    I have insatlled Visual Studio 2008. I have to create DLL in Project
    type Visual C++.
    Which Template i have to select to reate dll, MFC DLL or Class
    Library?.
    I have to call or import this dll in Windows Forms Application. How
    can i do this. Please give details procedure to do this.

    If we look at how  AFX_CLASS_EXPORT and AFX_CLASS_IMPORT  are defined in afxv_dll.h we see the following.
    #define AFX_CLASS_EXPORT __declspec(dllexport)
    #define AFX_CLASS_IMPORT __declspec(dllimport)
    So, when exporting our classes from our DLL we want the class declarations from the DLL to look like this:-
    class __declspec(dllexport) CMyClass : public CObject
    And, when importing our C++ classes into our application we want the class declarations from the DLL to look like this:-
    class __declspec(dllimport) CMyClass : public CObject
    OK, so here's how I do things.
    In the stdafx.h file for the export DLL, include two #defines at the bottom of the file like this:-
    #define _MYLIB_DLLAPI_
    #define _MYLIB_NOAUTOLIB_
    Now, in the main header file for your DLL, say mylib.h (the main 'point of entry' header for your DLL that you will include in you application later), add the following at the top:-
    // The following will ensure that we are exporting our C++ classes when
    // building the DLL and importing the classes when build an application
    // using this DLL.
    #ifdef _MYLIB_DLLAPI_
        #define MYLIB_DLLAPI  __declspec( dllexport )
    #else
        #define MYLIB_DLLAPI  __declspec( dllimport )
    #endif
    // The following will ensure that when building an application (or another
    // DLL) using this DLL, the appropriate .LIB file will automatically be used
    // when linking.
    #ifndef _MYLIB_NOAUTOLIB_
    #ifdef _DEBUG
    #pragma comment(lib, "mylibd.lib")
    #else
    #pragma comment(lib, "mylib.lib")
    #endif
    #endif
    Now, just declare all the C++ classes you want exported from the DLL like this:-
    (Note: Any C++ classes not declared with MYLIB_DLLAPI will not be exported from the DLL)
    class MYLIB_DLLAPI CMyClass : public CObject
    regards,
    Matt John
    complete variety of quilts is availabale here!
     PR: wait...
     I: wait...
     L: wait...
     LD: wait...
     I: wait...
    wait...
     Rank: wait...
     Traffic: wait...
     Price: wait...
     C: wait...

  • How do I call a LabVIEW created DLL from within Microsoft Excel (VBA)?

    Hi,
    I'm trying to get Microsoft Excel 2003 to call a function stored in a dll that I created using LabVIEW 7.1.  The function is very simple and is called "binary_file_to_ascii".  Basically it just reads a LabVIEW created binary spreadsheet file and outputs the columns as float arrays.
    The function arguments are as follows:
    INPUT : String that contains the path to the binary spreadsheet file
    OUTPUT : Number of rows in the spreadsheet
    OUTPUT : Number of columns in the spreadsheet
    OUTPUT : Float array containing the elements in column 1
    OUTPUT : Float array containing the elements in column 2..
    OUTPUT : Float array containing the elements in column 11
    However, for some reason there is something wrong with my VBA code and/or the way I created the DLL in LabVIEW because Excel crashes when it loads my DLL.
    What do I need to change in my VBA code or my LabVIEW DLL build settings to fix this?
    I've attached to this post a ZIP file that contains all my code and a sample binary file.
    Your help with this will be much appreciated.  Thanks!
    Richard
    P.S.  Here is the VBA code I'm using:
    Private Declare Function binary_file_to_ascii Lib "C:\temp\binary_file_to_ascii\binary_to_ascii.dll" _
    (ByVal binaryFile As String, ByVal nrows As Long, ByVal ncols As Long, ByVal column1 As Variant, _
    ByVal column2 As Variant, ByVal column3 As Variant, _
    ByVal column4 As Variant, ByVal column5 As Variant, _
    ByVal column6 As Variant, ByVal column7 As Variant, _
    ByVal column8 As Variant, ByVal column9 As Variant, _
    ByVal column10 As Variant, ByVal column11 As Variant)
    Private Sub load_binary_spectra()
      Dim nrows, ncols As Long
      Dim col1(), col2(), col3(), col4(), col5(), col6(), _
          col7(), col8(), col9(), col10(), col11() As Variant
      Dim lRetVal As Long
      Dim spectra_path As String
        spectra_path = "C:\temp\binary_file_to_ascii\sample_binary_file\sample_binary_file.dat"
        lRetVal = binary_file_to_ascii(spectra_path, nrows, ncols, _
                  col1(), col2(), col3(), col4(), col5(), col6(), _
                  col7(), col8(), col9(), col10(), col11())
        MsgBox (spectra_path)
    End Sub
    Message Edited by Richard Ballantyne on 07-25-2007 02:39 PM
    Message Edited by Richard Ballantyne on 07-25-2007 02:39 PM
    Attachments:
    binary_file_to_ascii.zip ‏192 KB

    Hi,
    I don't know anything about Visual Basic, but here's my guess.
    When you load the DLL with this line of code
    Private Declare Function binary_file_to_ascii Lib "C:\temp\binary_file_to_ascii\binary_to_ascii.dll" _
    (ByVal binaryFile As String, ByVal nrows As Long, ByVal ncols As Long, ByVal column1 As Variant, _
    You are defining how the parameters are sent. It seems that all are sent by value (ByVal), but in the DLL header, some of the function's
    parameters are defined as pointers(see the function prototype below, look for asterisk(*))
    void __stdcall binary_file_to_ascii(PStr binaryFile,
                                                    long *numberOfRows,
                                                    long *numberOfColumns,
                                                    float column1[],
                                                    float column2[],
                                                    float column3[],
                                                    float column4[],
                                                    float column5[],
                                                    float column6[],
                                                    float column7[],
                                                    float column8[],
                                                    float column9[],
                                                    float column10[],
                                                    float column11[]);
    Can you define in VBA that you want to use pointer instead? Maybe by using ByRef (as by reference).
    Hope this helps.

  • Creating dll and calling it in labview crashing the program

    Hi All,
    I am using labview from quite a long time.But this time i am stuck with dll.Not able to solve this issue.
    I have to communicate with FTDI chip.
    I have a VC++ Project to communicate with SPI of FTDI.That Code is working perfectly fine.
    Now I Have to automate that through LabVIEW. VISA Drivers i cant use in this. So Last option left is either to create dll or to make EXE out of it.
    I have tried by creating DLL and then calling it in LabVIEW by using Call Library Function Node.But its not helping me out every time LabVIEW is getting Crashed.
    Is there error in creation of dll or something i am not doing properly while calling?
    Thanks In Advance 
    Shweta
    Attachments:
    old_dolphin_sub_spi_func_ftdi.c ‏21 KB
    ftdi_write_read.vi ‏15 KB

    Which function call crashes LabVIEW?
    Have you tried switching the calling convention from stdcall to C for all of the DLL calls?
    Why are you converting a string to a number, instead of using a numeric constant directly? If you want a number in hex, you can right-click a numeric constant, make the radix visible, and switch it to hex display.

Maybe you are looking for

  • Using Apple's Magic Trackpad in Fireworks

    I am using Fireworks CS6 on the MacBook Pro 15inch Retina and I find that pretty much all of the gesture based finctions of the trackpad including 2 finger scrolling navigation, pinch zoom and (Option+ 2 finger) zoom does not work. Is the trackpad's

  • Message: You can't open the application Firefox because it may be damaged or incomplete

    I've been using Firefox for a long time. Today I decided to change the settings to delete my history when I closed the window. Now when I try to open up Firefox I get a continuous pinwheel. I deleted Firefox from my computer and reinstalled, but it s

  • Internet Sharing

    I have an old G4 MDD tower, with no airport card. I am in a house with the room I'm using way too far from the router to hardwire my mac in, and am trying to get a PC that has wireless in it to use to connect to the internet. I've searched and all I

  • Import Issues with PE7

    I recently imported over 11,500 photos from my old computer to my new computer using Photoshop Elements 7. 98% of these images had descriptive tags or categories assigned. Unfortunatly, only about 400 of the tags remained in place after the import. I

  • Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870080)(ERR=12514)

    Hello everyone, I'm a complete newbie here... but I wanted to share with you a problem that's driving me mad. I've got a database that has been monitored for quite a long time. But now, for some reason, it keeps showing errors intermittently. Working