Search in sources :

Example 1 with OleAuto

use of com.sun.jna.platform.win32.OleAuto in project jna by java-native-access.

the class Convert method toVariant.

/**
         * Convert a java value into a VARIANT suitable for passing in a COM
         * invocation.
         * 
         * <p><i>Implementation notes</i></p>
         * 
         * <ul>
         * <li>VARIANTs are not rewrapped, but passed through unmodified</li>
         * <li>A string is wrapped into a BSTR, that is wrapped into the VARIANT.
         *  The string is allocated as native memory by the VARIANT constructor.
         *  The BSTR needs to be freed by {@link com.sun.jna.platform.win32.OleAuto#SysFreeString}.</li>
         * </ul>
         * 
         * @param value to be wrapped
         * @return wrapped VARIANT
         */
public static VARIANT toVariant(Object value) {
    if (value instanceof VARIANT) {
        return (VARIANT) value;
    } else if (value instanceof BSTR) {
        return new VARIANT((BSTR) value);
    } else if (value instanceof VARIANT_BOOL) {
        return new VARIANT((VARIANT_BOOL) value);
    } else if (value instanceof BOOL) {
        return new VARIANT((BOOL) value);
    } else if (value instanceof LONG) {
        return new VARIANT((LONG) value);
    } else if (value instanceof SHORT) {
        return new VARIANT((SHORT) value);
    } else if (value instanceof DATE) {
        return new VARIANT((DATE) value);
    } else if (value instanceof BYTE) {
        return new VARIANT((BYTE) value);
    } else if (value instanceof Byte) {
        return new VARIANT((Byte) value);
    } else if (value instanceof Character) {
        return new VARIANT((Character) value);
    } else if (value instanceof CHAR) {
        return new VARIANT((CHAR) value);
    } else if (value instanceof Short) {
        return new VARIANT((Short) value);
    } else if (value instanceof Integer) {
        return new VARIANT((Integer) value);
    } else if (value instanceof Long) {
        return new VARIANT((Long) value);
    } else if (value instanceof Float) {
        return new VARIANT((Float) value);
    } else if (value instanceof Double) {
        return new VARIANT((Double) value);
    } else if (value instanceof String) {
        return new VARIANT((String) value);
    } else if (value instanceof Boolean) {
        return new VARIANT((Boolean) value);
    } else if (value instanceof com.sun.jna.platform.win32.COM.IDispatch) {
        return new VARIANT((com.sun.jna.platform.win32.COM.IDispatch) value);
    } else if (value instanceof Date) {
        return new VARIANT((Date) value);
    } else if (value instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(value);
        ProxyObject pobj = (ProxyObject) ih;
        return new VARIANT(pobj.getRawDispatch());
    } else if (value instanceof IComEnum) {
        IComEnum enm = (IComEnum) value;
        return new VARIANT(new WinDef.LONG(enm.getValue()));
    } else if (value instanceof SAFEARRAY) {
        return new VARIANT((SAFEARRAY) value);
    } else {
        return null;
    }
}
Also used : SAFEARRAY(com.sun.jna.platform.win32.OaIdl.SAFEARRAY) VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) CHAR(com.sun.jna.platform.win32.WinDef.CHAR) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) VT_VARIANT(com.sun.jna.platform.win32.Variant.VT_VARIANT) VT_BSTR(com.sun.jna.platform.win32.Variant.VT_BSTR) BSTR(com.sun.jna.platform.win32.WTypes.BSTR) Proxy(java.lang.reflect.Proxy) BYTE(com.sun.jna.platform.win32.WinDef.BYTE) LONG(com.sun.jna.platform.win32.WinDef.LONG) InvocationHandler(java.lang.reflect.InvocationHandler) Date(java.util.Date) SHORT(com.sun.jna.platform.win32.WinDef.SHORT) DATE(com.sun.jna.platform.win32.OaIdl.DATE) VT_DATE(com.sun.jna.platform.win32.Variant.VT_DATE) VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) VT_BOOL(com.sun.jna.platform.win32.Variant.VT_BOOL)

Aggregations

DATE (com.sun.jna.platform.win32.OaIdl.DATE)1 SAFEARRAY (com.sun.jna.platform.win32.OaIdl.SAFEARRAY)1 VARIANT_BOOL (com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL)1 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)1 VT_BOOL (com.sun.jna.platform.win32.Variant.VT_BOOL)1 VT_BSTR (com.sun.jna.platform.win32.Variant.VT_BSTR)1 VT_DATE (com.sun.jna.platform.win32.Variant.VT_DATE)1 VT_VARIANT (com.sun.jna.platform.win32.Variant.VT_VARIANT)1 BSTR (com.sun.jna.platform.win32.WTypes.BSTR)1 BOOL (com.sun.jna.platform.win32.WinDef.BOOL)1 BYTE (com.sun.jna.platform.win32.WinDef.BYTE)1 CHAR (com.sun.jna.platform.win32.WinDef.CHAR)1 LONG (com.sun.jna.platform.win32.WinDef.LONG)1 SHORT (com.sun.jna.platform.win32.WinDef.SHORT)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Proxy (java.lang.reflect.Proxy)1 Date (java.util.Date)1