Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

JNA library



The JNA library (see JNA) is a Java library which allows to interface Java code with C libraries, both for calling C functions from Java or for calling Java methods from the C code.

Overview

Appart from registering the C dlls, the JNA code does not involve any generation of C interface stubs such as JNI. You only have to declare an interface extending the com.sun.jna.Library interface in Java, and call this interface. For example:
      public interface MyCLibrary extends Library {      
        public void myFunction(int value);
      }     
Here if means that there is a function in the C dll called myFunction[1]
The declspec(dllexport) declaration is there to make the declaration available outside of the dll
:
      declspec(dllexport) void myFunction(int value);

Types correspondance

This paragraph presents the correspondancse between the Java and C types.

Note: Unsigned types use the same mappings as signed types. C enums are usually interchangeable with "int".

Simple types

The table of correspondance for the Java and C simple types is the following:
C type Java type Comment Example
bool boolean - C code: void receive(bool boolValue)
Java code: public void receive(boolean boolValue);
char byte - C code: void receive(char cValue)
Java code: public void receive(byte cValue);
int int - C code: void receive(int iValue)
Java code: public void receive(int iValue);
float float - C code: void receive(float fValue)
Java code: public void receive(float fValue);
double double - C code: void receive(double dValue)
Java code: public void receive(double dValue);
long NativeLong This is the com.sun.jna.NativeLong JNA class C code: void receive(long lValue)
Java code: public void receive(NativeLong lValue);
size_t long _ C code: void receive(size_t lValue)
Java code: public void receive(long lValue);
char* String - C code: void receive(char* sValue)
Java code: public void receive(String sValue);

Structure types

Array types

The table of correspondance for the Java and C simple arrays is the following:
C type Java type Comment
bool[] Pointer - C code: void receive(boolean bArray[])
Java code: public void receive(Pointer bArray);
int[dimension] int[] -
int[] Pointer - C code: void receive(int iArray[])
Java code: public void receive(Pointer iArray);
float[] Pointer - C code: void receive(float fArray[])
Java code: public void receive(Pointer fArray);
double[] Pointer - C code: void receive(double dArray[])
Java code: public void receive(Pointer dArray);
*char[] Pointer[] -

Notes

  1. ^ The declspec(dllexport) declaration is there to make the declaration available outside of the dll

See also


Categories: development

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence