Logo Search packages:      
Sourcecode: libjna-java version File versions  Download package

Object com::sun::jna::Function::invoke ( Object[]  args,
Class  returnType 
) [inline, package]

See also:
NativeLibrary::NativeLibrary(String,String,long) implementation

Definition at line 272 of file Function.java.

References invokeDouble(), invokeFloat(), invokeInt(), invokeLong(), invokePointer(), invokeString(), invokeStructure(), invokeVoid(), com::sun::jna::Structure::read(), com::sun::jna::Structure::useMemory(), and valueOf().

                                                   {
        Object result = null;
        if (returnType == null || returnType==void.class || returnType==Void.class) {
            invokeVoid(callingConvention, args);
            result = null;
        }
        else if (returnType==boolean.class || returnType==Boolean.class) {
            result = valueOf(invokeInt(callingConvention, args) != 0);
        }
        else if (returnType==byte.class || returnType==Byte.class) {
            result = new Byte((byte)invokeInt(callingConvention, args));
        }
        else if (returnType==short.class || returnType==Short.class) {
            result = new Short((short)invokeInt(callingConvention, args));
        }
        else if (returnType==char.class || returnType==Character.class) {
            result = new Character((char)invokeInt(callingConvention, args));
        }
        else if (returnType==int.class || returnType==Integer.class) {
            result = new Integer(invokeInt(callingConvention, args));
        }
        else if (returnType==long.class || returnType==Long.class) {
            result = new Long(invokeLong(callingConvention, args));
        }
        else if (returnType==float.class || returnType==Float.class) {
            result = new Float(invokeFloat(callingConvention, args));
        }
        else if (returnType==double.class || returnType==Double.class) {
            result = new Double(invokeDouble(callingConvention, args));
        }
        else if (returnType==String.class) {
            result = invokeString(callingConvention, args, false);
        }
        else if (returnType==WString.class) {
            String s = invokeString(callingConvention, args, true);
            result = s != null ? new WString(s) : null;
        }
        else if (Pointer.class.isAssignableFrom(returnType)) {
            result = invokePointer(callingConvention, args);
        }
        else if (Structure.class.isAssignableFrom(returnType)) {
            if (Structure.ByValue.class.isAssignableFrom(returnType)) {
                Structure s = 
                    invokeStructure(callingConvention, args, 
                                    Structure.newInstance(returnType));
                s.read();
                result = s;
            }
            else {
                result = invokePointer(callingConvention, args);
                if (result != null) {
                    Structure s = Structure.newInstance(returnType);
                    s.useMemory((Pointer)result);
                    s.read();
                    result = s;
                }
            }
        }
        else if (Callback.class.isAssignableFrom(returnType)) {
            result = invokePointer(callingConvention, args);
            if (result != null) {
                result = CallbackReference.getCallback(returnType, (Pointer)result);
            }
        }
        else {
            throw new IllegalArgumentException("Unsupported return type "
                                               + returnType
                                               + " in function " + getName());
        }
        return result;
    }


Generated by  Doxygen 1.6.0   Back to index