Re: Outlook 2003
Johannes Stille <[email protected]> Wed, 20 Sep 2006 16:21:17 +0200
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <[email protected]> |
Hello Edgar, hello everyone,
Edgar Johnson wrote:
> Thanks for the tip. That does work, however I had to get=20
> away from the stubs that were generated via the typebrowser=20
> and use the DispatchPtr. The generated stubs did not=20
> generate a method that used an Object or an Integer as a=20
> parameter. The method I want to use, only accepts a Variant.
Unfortunately the handling of variant and optional arguments in dispatch
interfaces is quite convoluted.
Optional arguments need to be passed as variants because an argument not
actually present is passed as variant of type VT_ERROR, code
DISP_E_PARAMNOTFOUND. I do not know why those variants generally are
passed
BYREF - maybe it's a performance issue (passing a pointer instead of
copying
content).
So the type browser (e.g. for MS-Office applications) correctly
generates
many functions with many Variant.ByrefHolder arguments that really are
optional integers, but it's possible to make filling these arguments
quite
easy. (I still am a big fan of the type browser, and I think it's a tool
many java developers are waiting for... I use it successfully for
MS-Word
access; I had to make some modifications first, though. They just need a
little cleanup before I'll try to reach the jawin maintainers about
integrating them.)
One of the simplifications is creating variants from values of the
underlying types. I propose the following patch:
--- src/org/jawin/Variant.java.bak 2004-07-31 23:20:06.000000000
+0200
+++ src/org/jawin/Variant.java 2006-07-07 11:33:44.166280000 +0200
@@ -131,6 +131,25 @@
}
}
=20
+ public Variant() {
+ vt =3D VarTypes.VT_EMPTY;
+ }
+=09
+ public Variant(int i) {
+ vt =3D VarTypes.VT_I4;
+ lVal =3D i;
+ }
+=09
+ public Variant(String s) {
+ vt =3D VarTypes.VT_BSTR;
+ bstrVal =3D s;
+ }
+=09
+ public Variant(boolean b) {
+ vt =3D VarTypes.VT_BOOL;
+ boolVal =3D b;
+ }
+=09
/**
* marshall an object onto an output stream. The object will be
marshalled
* following these rules (please notice that primitive types
should be=20
Add similar constructors as you please. ;-)
This makes it possible to just pass a "new Variant(1)".
I think similar constructors for Variant.ByrefHolder would be useful as
well
- construct an ByrefHolder containing a variant containing the value
passed
in. The I could just pass a "new Variant.ByrefHolder(1)" instead of a
"new
Variant.ByrefHolder(new Variant(1))".
BTW, is jawin still actively maintained? I just found the
GetActiveObject()
patch by Georg Ragaller, dating from April 2005, and the answer form
Morten
Anderson sounded as if that patch was going to be integrated into the
source
tree. But as of two weeks ago, I did not find that code in the CVS
source
tree. I'll give it a try nevertheless - first results are looking quite
good.
Regards,
Johannes Stille