Friday, August 3, 2012

Invoking native C/C++ lib using groovy and JNA

So as a continuation of the last post http://orphanware.blogspot.com/2012/08/making-c-available-through-native-calls.html....here is how to invoke using groovy again make sure you get the jna.jar and platform.jar from the interwebs!

here is the groovy code:

import com.sun.jna.*;

def lib = NativeLibrary.getInstance("mylib")
def helloWorld = lib.getFunction( "MYLIB_helloWorld" )

/*
if args do this
Object[] args = new Object[2];
args[0] = "arg1"
args[1] = "arg2"
*/

helloWorld.invokeVoid(null)

then run with

groovy -cp jna.jar:.  -Djna.nosys=true helloworld.groovy

for more invoke options see http://jna.java.net/javadoc/com/sun/jna/Function.html

No comments:

Post a Comment