Click here to Skip to main content
15,894,176 members
Everything / JNI

JNI

JNI

Great Reads

by Android on Intel
This blog outlines the steps needed to integrate Intel’s AES-NI instructions into an Android app via the OpenSSL library.
by Android on Intel
This document is focused on creating OpenCV-enabled applications for Android. If the target operating system of your application is Windows
by Android on Intel
In this paper, we introduce some of the new features in ART, benchmark it against the previous Android Dalvik* runtime, and share five tips for developers that can further improve application performance.
by Android on Intel
This article walks through an example Android application that offloads image processing using OpenCL™ and RenderScript programming languages.

Latest Articles

by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
by mohamadArdestani
get shutdown message in java application with jni
by YevheniyK
The article describes a general approach to using Cocos2d-x on top of native components and relevant coding specifics for Cocos2d-x, iOS and Android.
by Luca Basso Ricci
How to build the JNI signature for a Java method

All Articles

Sort by Updated

JNI 

12 May 2021 by 15160877
I want to send an empty hashmap from java to C. After that, I need to store data from C to hashmap and again pass it to java. I can now access my java functions from C. But, now I want to pass a hashmap from java and store the data and pass the...
16 May 2021 by 15160877
I am trying to pass a LPWSTR to java via JNI. But, it only passes the first character of the string. Can someone suggest what to do? I'm passing the string like the following: jstring k = (*env)->NewStringUTF(env, lpstr); ...
24 Jun 2021 by 15160877
I am trying to pass a string value from java to c. And, a hashmap from C to java. I am trying to pass this using same method in C. But, I can't do that in a same method. I need the string data to fill my hashmap. So, I need to do it inside a...
23 Nov 2010 by Aescleal
If you post (a) the Java you're using and (b) what the error is people might be able to help a bit more.I don't know anything about JNI but have you considered that in the second lump of code you're using an uninitialised variable?In the first lump you also cast a const pointer to a...
11 Sep 2012 by AhmdAxf
for the System.loadLibrary() call the dll file should be in path of java i.e system32 but i would recommend System.load() instead by which you would be able to give full path of the dll file and use it in any other java app usin that jar
11 Sep 2012 by AhmdAxf
Hi All,I am working on a project similar to embedding opengl inside java in which a an animated figure is drawn into an AWT canvas using JNI and AWT native interface. I have a third party application software whose method for live video is providing the same functionality. I have played...
16 Mar 2013 by Ahsetau
I have a test case where I am trying to access the C code from my JAVA program using JNI. Steps involved are as follows : 1. A JAVA program calling the native methods : public class RunnerClass{ public native void win32_svc_install(); static{ System.loadLibrary("testDll"); ...
13 Jul 2011 by Albert Holguin
Look at the libraries specified in the linker options of the functioning code and make sure that all those are also specified in the linker options of the code giving you the errors. Like Richard mentioned, this looks like you're missing .libs.
3 Feb 2004 by alfreds
A near to perfect clone of the very popular Yahoo messenger. Purely written in Java and SWING, this messenger also uses the capabilities of JNI and JAWT to provide some features.
16 May 2008 by Alice Huang
In this tutorial, I will try to explain how to use JNI auto loader for JAR file.
23 Apr 2017 by amir tarek
i make a simple c function in Visual studio 6 this is the code #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) { return TRUE; } extern "C" __declspec(dllexport) char __stdcall GetCompanyCode() { return 1; } i need to call the...
12 Feb 2015 by Android on Intel
This blog outlines the steps needed to integrate Intel’s AES-NI instructions into an Android app via the OpenSSL library.
6 Jul 2015 by Android on Intel
This document is focused on creating OpenCV-enabled applications for Android. If the target operating system of your application is Windows
20 Jul 2015 by Android on Intel
In this paper, we introduce some of the new features in ART, benchmark it against the previous Android Dalvik* runtime, and share five tips for developers that can further improve application performance.
1 Oct 2015 by Android on Intel
This article walks through an example Android application that offloads image processing using OpenCL™ and RenderScript programming languages.
16 May 2012 by Anil Kumar 23
HiI m trying to create a header file for a sample helloworld program calling a native funtion from native dll to be made with the help of this header file.I have compiled the java file but now when i m creating the header file m getting an error...error: cannot access HelloWorldclass...
4 Oct 2011 by anktrive
Hi, I am new to JNI and I have been trying to write a simple program to call Java code from C++. I am facing problem in creating the JavaVM from C and am getting the Linker error. I have tried changing the GNU library files in dev C++ (I am using Dev c++ compiler) but no luck so far....
1 Aug 2010 by Anoop SL
Dear Coders,I'm implementing a browser based application which accesses some native c++ calls runtime. I'm using Http at browser and calling my native c++ using java script and JNI. So far I'm successful to some degree only with safari browser. Can somebody enlighten me on why this is...
18 May 2021 by another_newbie
By looking at the definition of jbyte in jni.h I have: typedef int8_t jbyte; /* signed 8 bits */ So is it is always safe to convert jbyte to a signed integer without casting? What I have tried: So far I have tried int8_t
27 Dec 2011 by Areff
Hi, every body i have developed a java class named A that uses another class named B , both of them is in package com.kkp ,the class B have some native methods that implemented in B.cpp & B.hi have used g++ for compiling the cpp file and creating a dll (B.dll).til here every things is...
20 Aug 2013 by Buddhi Chaturanga
I constructed a java program using netbeans IDE that has ability to connect with a respective DLL; I want to connect and interchange data between my java program(.jar) and VSC++ program(.exe) through DLLs.JNI uses single Dll to invoke C/C++ function in native manner,In order to increase the...
20 Aug 2012 by Christian Graus
You're a developer, why not write a program to download the files, or even better, use an FTP program. How is this a programming question ?
9 Jan 2011 by CPallini
You need to perform no conversion: JNI makes the Java's String class content available to native functions as jstring type. Have a look at the following documentation page for detailed info Basic Types, Strings and Arrays[^].:-)
28 Aug 2015 by CPallini
See this Stack Overflow question: "Returning Mat object from native code to java in OpenCV"[^].
19 May 2015 by cth027
A tutorial to master the Java Native Interface with C++
3 Jun 2014 by E.F. Nijboer
Git is a distributed version control system and github is an online location for sharing repositories. You cannot debug it directly. You need to download it or use:git clone --bare https://github.com/FreeRDP/FreeRDP.gitOf course you must have git installed. Download link:...
9 Jan 2011 by Espen Harlinn
the jni jstring is a representation of java.lang.String - no conversion needed.RegardsEspen Harlinn
31 Jul 2011 by Espen Harlinn
You'll find the JNI code here:SWT: The Standard Widget Toolkit[^]I know SWT is not Swing - but SWT has the required JNI code.Remember that Swing is built on top of the original objects and framework of AWT.Inside the $(JDK)\include folder you'll find jawt.hInside the...
5 Oct 2011 by Espen Harlinn
It's customary to locate the java runtime trough settings from the registry, and then load the dll dynamically.Have look at:Jace[^]Jace offers some additional features you might find interesting too.[Update]The _imp__ prefix indicates that you have a problem with your library - I...
14 Jul 2021 by getrelax
I want to connect and access to HSQL DB from C#. I am trying to use JNI to invoke Java code in C# environment. The challenge is how to write java import statement in C# environment. What I have tried: I used the reference shown in this link...
7 Feb 2015 by guest000007
Install the latest MinGW with msysPut this new user variable in System properties -> Advanced -> Environment Variables:PATHC:\MinGW\binOpen msys.bat$ cd "path" // point to your folder where is the NIST makefile$ makeand hopla, the assess.exe is ready for use.
30 Jul 2011 by Himanshu Bajpai
I am new to java .I add one extra menu on system menu now I want to handle an event on the system menu in java swings application i prepare a dll for that in c++ and i am unable to handle the event on system menu through dll using wndproc method through JNI if there any one who helps me to do this.
3 Aug 2011 by Himanshu Bajpai
sir I have added one own menu item in window menu using jni,vc++,java. sir I want to handle event on that item using jni.how it can be possible. sir this can be done by jinvoke package in java.This package contain user32 class.so it can be done by jinvoke package. But sir I can't use this...
25 Nov 2010 by Igor Kushnarev
The techniques to use SVG in the ImageView control
2 Dec 2010 by jackyxinli
Using JNI and COM technology generate Word documents in Java under Windows platform
20 Aug 2013 by KarstenK
The JNI interface works fine if you handle it very carefully.Everything should be transfered by value and then work on a local copy. Do dont work with pointer from C++ in Java and vice versa or some strange exceptions will hurt you :mad:That looks interesting for you:Sample JNI...
21 Aug 2013 by KarstenK
Consider using a notification model. The callee changes the value and the called is performing some actions. like notifying other modules.That event driven model has a good performance and stability.
20 Mar 2015 by KarstenK
I found this fine Java Programming Tutorial for JNI with example for int array.Very important is to release all memory carefully or the jni gets into trouble without any clear errors.
21 Mar 2015 by KarstenK
To be honest: The simplest and savest way is to use one dimension arrays with native data types and AVOID structs. Java and C have different memory layouts. Microsoft has solved this mess on its .net-languages.I would extend the interfaces of rhe func with size information:JNIEXPORT...
26 Oct 2016 by KarstenK
You must correct initialize the MFC runtime before the first use, like it is here described.For updating the UI you must implement an interface function with JNI to the MFC-dll, in which the update (as message parameter) the signaled. Because the JRE/JNI and the MFC are in different...
26 Oct 2016 by KarstenK
The easiest way is to setup a timer in java and poll for the actual status in C++. It makes a lot sense to poll "only once" in a second.
31 Oct 2016 by KarstenK
The called function isnt properly exported with JNI from your C dll, maybe it is only the wrong data type as parameters. The first is ALWAYS the JNI pointer. Here is a fine looking tutorial where all is explained.JNI works that way, so take care to implement the c-dll in this manner.
23 Apr 2017 by KarstenK
You must carefully read and understand the error message. Here is "Error looking up function 'GetCompanyCode': The specified procedure could not be found." So the linker says that dll is found but the function not. Check with the good olddepedency walker that the function name is properly...
12 Jun 2018 by KarstenK
Normally JNI works and you have missed some details. Read the article Calling Java from C++ with JNI in which the JNI is used as I had been working with it. Check that the packages, classes and functions are public. At last you can try to do your work in Java and only export the results as...
9 Aug 2019 by KarstenK
If you write on the port you should check that the data is written and than close the port. It is best to open only when needed and than close again. Read about the specific timeouts of that port. Be precise about not opened multiple ports or double close ports, this can lead to strange...
6 May 2021 by KarstenK
Be happy that it works and move on. Transfering complex objects between different runtimes isnt possible because of memory layout. You may transfer some byte array in which the data is an reinterpret it. Like struct Data { int i; int lenstr; ...
16 May 2021 by KarstenK
Working with strings isnt so easy at all because every string has "under the hood" some encoding logic. This mean HOW the buffer of bytes is interpreted to the human readable string. Try also Memory view to see the details byte by byte. For this...
19 Feb 2013 by Leo Chapiro
You have to link with JVM's library (add some reference to libjvm.a to the tcc's command line).If you don't have a precompiled jvm.lib file for TurboC++, there is another option - link with the jvm.dll file and export all the methods from JVM manually. This uses the...
23 Nov 2010 by lpbolg
//this's jni function in dll;JNIEXPORT jstring JNICALL Java_vc_CallVc_getActiveWindowTitle//get title(JNIEnv * jn, jclass){ jstring str; const char *strTitle =GetStringUTFChars( str , 0); ...
23 Nov 2010 by lpbolg
Nobody help me ?????:confused:
15 Sep 2016 by Luca Basso Ricci
How to build the JNI signature for a Java method
3 Feb 2011 by Manfred Rudolf Bihy
JNI is javas native interface and was meant to integrate system specific processes with the java world. Since programs\libraries that are used on one OS can't be directly used on another OS, I would say that you would have to port the library/program from windows to whatever OS you're planning...
12 Jun 2018 by Manish Sharma
I need to call some Java methods using C/C++ and then I need to use DPI in UVM or system verilog to call C methods. I dont have access for JAVA files or JAVA classes. I have a .jar file in which my class is present of which methods I need to access. I am using path of that .jar file in ...
13 Dec 2013 by manish yadav
I am using http://www.sqlite.org/c3ref/open.html as a reference for using the sqlite c for opening the dbi m calling like this package com.example.offline; public class NativeLib { static { System.loadLibrary("sqlite3"); } ...
3 Dec 2012 by Manish_Mohan
Hi all,Does anyone know how to resolve this exception.## A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7a83f0, pid=6320, tid=6328## JRE version: 7.0_05-b05# Java VM: Java HotSpot(TM) Client VM (23.1-b03...
10 Nov 2015 by mayooran99
I have the a JNA structure which is throwing InvalidMemoryAccessException occasionally. Without changing the code,when I run it, it runs at times. At times it throw the exception as shown below.Exception in thread "main" java.lang.Error: Invalid memory accessat...
28 Apr 2012 by Mehdi Gholam
Take a look here :http://www.haskell.org/haskellwiki/Applications_and_libraries/Interfacing_other_languages#Java[^]You could create a webservice also :http://stackoverflow.com/questions/6663888/web-service-frameworks-in-haskell[^]
22 Oct 2013 by Member 10286395
he code below gives me all elements of any window but i want to know the particular button/link/textbox accessed by user ...User32.INSTANCE.EnumChildWindows(GetForegroundWindow(), new User32.WNDENUMPROC() { int count = 1; ...
16 Jul 2014 by Member 10378849
I search for solution 3 day still I cant find.My java file work normally and no error. I copied my java file "I2CInterface.java" to "jdk/bin" directory. Then "javac I2CInterface.java" the I2CInterface.class created succesfully. But "javah -jni I2CInterface" give error class couldnt found....
18 Sep 2016 by Member 12373848
I am trying to write DVD RW / CD using IMAPI 2.0 with C++. The created dll is being called from a Java Application.I am getting a crash in code which is the following :## A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at...
26 Oct 2016 by Member 12373848
I am creating a dll using IMAPI 2.0 with C++, can anyone help in how to monitor progress of burn & conitinuously send updates from dll to Java.What I have tried:I was trying to attach IDiscFormat2Data Event to burn thread. But how send this update continuosly to Java.
26 Oct 2016 by Member 12373848
How to call a MFC dll from Java. So that it feels as if Java launched the MFC UI.I am developing a MFC dll using IMAPI 2.0 with C++ to burn data on DVD/CD. I want to call this dll from Java & hence the run MFC dll with its UI. This will help in monitoring the burn process.What I have...
1 Nov 2016 by Member 12373848
I am developing a JavaFX application & a C++ dll whose method i want to call from JavaFX (java code). So, i have placed the dll in project directory, getting the working directory during runtime , hence creating the path to dll , setting the same path value to "java.library.path" & then loading...
6 May 2021 by Member 15076657
I want to access my c code from java and get data from C struct using JNI. I want to achieve this using hashtable or hashmap. Here is my C struct: struct process { char str[]; char strr[]; int i; }; struct process *ptr; Now, I want to pass the...
9 May 2021 by Member 15076657
I am using this as a reference to call my java class inside C program. But , JVM is not launching. Here is my code for launching jvm.
10 May 2021 by Member 15076657
I'm trying to run an .exe. When it runs, it shows the following error. Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries What does this mean? JNIEnv* create_vm(JavaVM** jvm) { //JavaVM*...
13 May 2021 by Member 15076657
I have passed a hashmap from java to C. Now, I need to fill the hashmap and pass it back to java. This is my java code. Main.java import java.util.*; public class Main { static { System.loadLibrary("Tests"); } public void doProcess()...
14 May 2021 by Member 15076657
I have been trying data from C file to java using JNI. But, when I try to pass it, the following error occurs in eclipse. # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at...
18 Apr 2012 by Member 8054791
Wlan.javapub...
11 Feb 2013 by Member 8661141
I have to return a array of structure values from c++ (jni) to java. I have the c++ struture as followsMyCStructure{byte *Data;int dataLength;int width;int height;}mycstr;And i have my java structure aspublic class MyJavaStructure{ public byte[] Data; public...
15 Sep 2018 by mohamadArdestani
get shutdown message in java application with jni
4 Sep 2014 by mohit_ranjan143
please provide the full code fro this android phonegap plugin's java script calli required urgently
19 Feb 2013 by Moorthy Rajendran
JNI_CreateJavaVM(&jvm, (void **)&env, &args);tcc C:\TurboC++\Disk\TurboC3\BIN\CTest.c -I "C:\Program Files\Java\jdk1.6.0_16\include" -I "C:\Program Files\Java\jdk1.6.0_16\include\win32" -I "C:\Program Files\Java\jdk1.6.0_16\lib" -shared -o CTest.dllError: tcc: undefined symbol...
2 Nov 2010 by Nagy Vilmos
The JVM used inside a browser are 'sandboxed'. They have restricted access outside of the browser to prevent malicious code damaging the client machine.If you are [still] experiencing problems with calling your external processes, I would recommend checking the requirements for supporting...
12 Apr 2017 by Nick_3141592654
It's not possible to use C++ without JNI - the point is that JNI *IS* native code, i.e. the very fact that you want to use C++ (or C) means that you are using a native library, within a Java environment => JNI. Remember that you only need to provide the JNI wrapper code for your API between the...
6 May 2021 by OriginalGriff
Repost: deleted. This is the same question you asked an hour ago: Access a C structure array from java using JNI[^]
9 May 2021 by OriginalGriff
If you don't understand an error message, Google it: Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries - Google Search[^] What it means is that a DLL is missing, or incompatible with the...
14 May 2021 by OriginalGriff
Repost: deleted. How many times are you going to post the same thing until you start listening and actually learning?
24 Sep 2012 by pasztorpisti
What about checking out and modifying existing code? How to Call Java Functions from C Using JNI[^]
21 Aug 2013 by pasztorpisti
What is "loading same DLL simultaneously"? First: If you start a VC++ program that loads a DLL and you start a Java program that loads the same DLL then you have created two processes that have nothing to do with each other so your assumption that you require some kind of IPC to communicate...
18 Sep 2016 by Patrice T
Even with best will, it is not possible to help you with this.You should read thisAsking questions is a skill[^]
23 May 2013 by PraveenOjha
An android game using NDK JNI and Java.
19 Mar 2015 by rahul15001
I have a int array like int[][] arrays = { array1, array2, array3, array4, array5 };where array1=30,40,20,40 ,array2=40,20,30,30 and I am trying to send this array to C with using JNI. I could not find any clear solution for this. I have tried to take this int as a intarray but no success.Is...
21 Mar 2015 by rahul15001
I have a int array likeint[][] coordinates = {{346, 640, 499, 666},{555, 640, 675, 666}};and I am trying to send this array to C with using JNI. I could find clear solution for one dimensional array but not for multidimensional array.public class PopulateCoordinates{public native...
22 Mar 2015 by rahul15001
I have a string array like {"myname","yourname","hisname"} and I am trying to send this array to C with using JNI. I could not find any clear solution for this. I have tried to take this string as a chararray but no success.Is there a way to do this?
3 Jun 2014 by RaiBnod
I have imported the git project in my workstation, and now i want to debug the https://github.com/FreeRDP/FreeRDP/tree/master/client/Android/FreeRDPCore path project. Means want to debug the FreeRDPCore project to work with that project.Have you any idea under debugging it, please your help...
2 Feb 2011 by Reza Oruji
Hi,I have written a Java program that uses jni in windows.Now I want to know, if this program is portable and if I can run it in another OS?
21 Jan 2015 by Richard Chambers
Exploring how to embed a Java VM into a C application and developing a native library for a Java application using JNI.
31 Jul 2011 by Richard MacCutchan
I don't think you can do this, all events will be handled by the JVM so your wndproc procedure will not get called. Espen has given a great explanation of this.
3 Oct 2011 by Richard MacCutchan
See here[^] to check your code is following the correct rules. Also, make sure you have defined your JNI calls within extern "C" {} blocks, to prevent name mangling by the compiler.
4 Oct 2011 by Richard MacCutchan
I don't know why this happens BUT:In your C code, if you replace the line:res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);with// this should contain the path to the JVM DLL fileHINSTANCE hVM = LoadLibrary("C:\\Program Files (x86)\\Java\\jre6\\bin\\client\\jvm.dll");if (hVM...
5 Oct 2011 by Richard MacCutchan
My apologies but I was compiling as C++, which does not work for standard C. Modify the code between the lines #ifdef JNI_VERSION_1_2 and #else as follows:#ifdef JNI_VERSION_1_2// definitions required to get the proc address HINSTANCE hVM; typedef jint (CALLBACK *fpCJV)(JavaVM**,...
27 Dec 2011 by Richard MacCutchan
If you do not have the dll in the default directory then you should add the full path to your System.loadLibrary() call.
22 Mar 2015 by Richard MacCutchan
It is not really clear what the issue is, but I suggest you take a look at https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html[^], which explains how to pass different types between Java and C/C++.
19 Sep 2016 by Richard MacCutchan
No you have not tried every possible solution, because I told you yesterday in http://www.codeproject.com/Questions/1130172/Csharp-code-to-JAVA-code[^] what you need to do. So now you need to go back and do it. The only way to interface between Java and a C/C++ dll is by using the JNI. And you...
26 Oct 2016 by Richard MacCutchan
See jni mfc - Google Search[^].Also, you already posted this question at How to monitor progress of burn using IMAPI 2.0 and pass updates to java[^]. Please do not repost.
6 May 2021 by Richard MacCutchan
This is effectively the same question as Access a C structure array from java using JNI[^]. Please do not repost.
6 May 2021 by Richard MacCutchan
Quote: Can I pass the data using Hashtable or Hashmap? Or can I pass the struct array directly to java? Is there any decent way for doing this? Sadly, no. The Java Native Interface is designed to allow C programmers to write support libraries...
9 May 2021 by Richard MacCutchan
I do not know where you found that code but the official documentation is different: The Invocation API[^]. Also why do you write: mbstowcs(t, "C:\\Program Files (x86)\\Java\\jdk-16.0.1\\jre\\bin\\server\\jvm.dll", 400); jvm_dll =...