NativeCall

Call native methods from Java without JNI

NativeCall lets you call native methods from Java without JNI code. The current version 0.4.1 supports structs, Strings, primitive types (int and boolean), byte and char arrays and output parameters. NativeCall is implemented for the Windows platform. With NativeCall, you can call all methods implemented in any DLL.

Download

Quick start

  1. Download NativeCall.
  2. Extract nativecall-0.4.1.jar and nativeloader-200505172341.jar.
  3. Make sure both JAR files are in your classpath.
  4. Extract the native library (NativeCall.dll).
  5. Read the Apidocs.
  6. Try the examples below.

Example code

Copying a file to a new one using the Windows API

import com.eaio.nativecall.*;

NativeCall.init();
IntCall ic = new IntCall("CopyFileA");
ic.executeCall(new Object[] {
    "test.txt", "test_copy.txt", Boolean.FALSE });
ic.destroy();

Setting a file’s attributes to be hidden

import com.eaio.nativecall.*;

NativeCall.init();
IntCall setFileAttributesA = new IntCall("SetFileAttributesA");
boolean success = setFileAttributesA.executeBooleanCall(new Object[]
 "documents/test.txt", new Integer(2) });
setFileAttributesA.destroy();

Working with structs to create a file, obtain the file handle and close the handle

import java.io.*;
import com.eaio.nativecall.*;

NativeCall.init();

IntCall createFileA = new IntCall("CreateFileA");
IntCall closeHandle = new IntCall("CloseHandle");

byte[] securityAttributes = new byte[12];
securityAttributes[0] = (byte) 12;

int fileHandle = createFileA.executeCall(new Object[]
    "documents/file_management_test.txt",
    new Integer(0x80000000 | 0x40000000 | 0x00010000),
    null, securityAttributes, new Integer(2), null, null });

boolean closed = closeHandle.executeBooleanCall(new Integer(fileHandle));

createFileA.destroy();
closeHandle.destroy();

Who uses NativeCall?

Other resources

Subscribe

RSS 2.0, Atom or subscribe by Email.

Top Posts

  1. DynaCloud - a dynamic JavaScript tag/keyword cloud with jQuery
  2. 6 fast jQuery Tips: More basic Snippets
  3. xslt.js version 3.2 released
  4. xslt.js version 3.0 released XML XSLT now with jQuery plugin
  5. Forum Scanners - prevent forum abuse
  6. Automate JavaScript compression with YUI Compressor and /packer/

Navigation