[JNA 4.1.0] Calling COMLateBindingObject.setProperty throws java.lang.IllegalArgumentException

79 views
Skip to first unread message

Athena

unread,
Feb 9, 2015, 10:01:24 AM2/9/15
to jna-...@googlegroups.com
Hi,

I'm currently trying to call Outlook COM interfaces based on JNA 4.1.0.
When trying to setBodyFormat of MailItem, I encountered the java.lang.IllegalArgumentException, with call stack listed below.

I searched the web without helpful info. Could you please give some advice? Thank you!


#Problem details#

I'm simply using setProperty("BodyFormat", (int) 1); to set the format to HTML.

The COMLateBindingObject::setProperty is:
    protected void setProperty(String propertyName, int value) {
        this.oleMethod(OleAuto.DISPATCH_PROPERTYPUT, null, this.getIDispatch(),
                propertyName, new VARIANT(value));
    }

Exception info and call stack:
java.lang.IllegalArgumentException: Can not set com.sun.jna.platform.win32.WinDef$LONG field com.sun.jna.platform.win32.Variant$VARIANT$_VARIANT$__VARIANT.lVal to java.lang.Integer
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:758)
at com.sun.jna.Structure.setFieldValue(Structure.java:591)
at com.sun.jna.Structure.setFieldValue(Structure.java:585)
at com.sun.jna.Structure.writeField(Structure.java:749)
at com.sun.jna.Union.writeField(Union.java:129)
at com.sun.jna.platform.win32.Variant$VARIANT.setValue(Variant.java:240)
at com.sun.jna.platform.win32.Variant$VARIANT.setValue(Variant.java:231)
at com.sun.jna.platform.win32.Variant$VARIANT.<init>(Variant.java:178)
at com.sun.jna.platform.win32.COM.COMLateBindingObject.setProperty(COMLateBindingObject.java:546)
at com.siebel.applets.email.CSSOLMailItem.setBodyFormat(CSSOLMailItem.java:47)


I also tried to call setProperty("BodyFormat", (short) 1); still got similar issue. 

java.lang.IllegalArgumentException: Can not set com.sun.jna.platform.win32.WinDef$SHORT field com.sun.jna.platform.win32.Variant$VARIANT$_VARIANT$__VARIANT.iVal to java.lang.Short
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:758)
at com.sun.jna.Structure.setFieldValue(Structure.java:591)
at com.sun.jna.Structure.setFieldValue(Structure.java:585)
at com.sun.jna.Structure.writeField(Structure.java:749)
at com.sun.jna.Union.writeField(Union.java:129)
at com.sun.jna.platform.win32.Variant$VARIANT.setValue(Variant.java:237)
at com.sun.jna.platform.win32.Variant$VARIANT.setValue(Variant.java:231)
at com.sun.jna.platform.win32.Variant$VARIANT.<init>(Variant.java:173)
at com.sun.jna.platform.win32.COM.COMLateBindingObject.setProperty(COMLateBindingObject.java:559)


Any advice would be appreciated!


Thanks,
Athena

Athena

unread,
Feb 9, 2015, 9:12:26 PM2/9/15
to jna-...@googlegroups.com
Some additional info from Outlook TypeLib:

HRESULT BodyFormat([in] OlBodyFormat BodyFormat);

    enum {
        olFormatUnspecified = 0,
        olFormatPlain = 1,
        olFormatHTML = 2,
        olFormatRichText = 3
    } OlBodyFormat;

So in java codes calling JNA, per my understanding, calling setProperty(String propertyName, int value) method is correct.

siebens...@mcmnet.de

unread,
Feb 18, 2015, 8:30:58 AM2/18/15
to jna-...@googlegroups.com
Hello Athena,

it seems, that it's not the problem to call setProperty() but to call the constructor from VARIANT?!?

Do you have tried to call simply "new VARIANT(1)" ?
Do you have some context for your problem? Is your program running in a multi-classloader-context? Do you have
a fully initialized Outlook-COM-Object already? Or do you have called CoInitialize() first?

If you can give me some more details, perhaps I can help you. :-)

Sincerly,
                      Siebenschläfer

siebens...@mcmnet.de

unread,
Feb 18, 2015, 12:31:26 PM2/18/15
to jna-...@googlegroups.com

Ok... there seems to be a problem in VARIANT with numeric types... :-(

I had the same problem at another location.

Here is a workaround to set a numeric (integer) property:

long value = 1;
VARIANT v
= new VARIANT();
v
.setValue(new VARTYPE(com.sun.jna.platform.win32.Variant.VT_I4), new com.sun.jna.platform.win32.WinDef.LONG(value));
setProperty
("BodyFormat", getIDispatch(), v);

Hope that helps.

Sincerly,
                             Siebenschläfer

Reply all
Reply to author
Forward
0 new messages