Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

How to Call Java Functions from C Using JNI

, 13 Jan 2008 CPOL
This article covers calling Java functions from C using JNI. It also covers passing/returning simple parameters, arrays, and structure arrays in Java functions.
src_cjnijava.zip
Java Src
TestStruct
CTest
CTest.dsp
CTest.dsw
Debug
public class HelloWorld 
{
      public static void main(String args[]) 
      {
         System.out.println("Hello World!");
         System.out.println("This is the main function in HelloWorld class");
      }
      public static void TestCall(String szArg)
      {
      	System.out.println(szArg);      
      }
      public static int DisplayStruct(ControlDetail ctrlDetail)
      {
      	System.out.println("Structure is:\n-------------------------");
      	System.out.println("Name:" + ctrlDetail.Name);
      	System.out.println("IP:" + ctrlDetail.IP);
      	System.out.println("Port" + ctrlDetail.Port);
      	return 1;     	
      }
      public static void DisplayStructArray(WorkOrder ArrWO[])
      {
      	System.out.println("WorkOrders are Given hereunder:\n----------------------------");
      	for(int i = 0; i< ArrWO.length;i++)
      	{
      		System.out.println("<---Work Order Number:" + String.valueOf(i+1) + "<---");
      		System.out.println("Sum_Serial_ID: " + ArrWO[i].sumSerialId);
      		System.out.println("Access_Number: " + ArrWO[i].accessNumber);
      		System.out.println("Action_Type: " + ArrWO[i].actionType);
      		System.out.println("Effective_Date: " + ArrWO[i].effectiveDate);
      		System.out.println("Fetch_Flag: " + ArrWO[i].fetchFlag);
      		System.out.println("Reason: " + ArrWO[i].reason);
      		System.out.println("Access_Source: " + ArrWO[i].accessSource);
      	}
      	
      }
      public static Object ReturnObjFunc()
      {
      	System.out.println("Going to return an object from java");
      	ReturnData RetData = new ReturnData(1,"Successfull function call");
      	return RetData;
      }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ajalilqarshi
Software Developer (Senior)
United Kingdom United Kingdom
Ahmad Qarshi is an IT Consultant and have good expertise in different development technologies. He loves to code in .NET, JavaFX, Delphi, XSLT/Schematron. Above all very keen to learn new stuff Smile | :)

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 13 Jan 2008
Article Copyright 2008 by ajalilqarshi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid