Call a Method with an [out] Parameter

tlb2java maps COM methods to Java methods with the same name. If name collisions occur you can use the -rename option. Java does not have a pass-by address syntax. To support COM methods that have [out] parameters, tlb2java generates an array type for [out] parameters. So, the pVal parameter in this IDL fragment:

GetBSTR([out] BSTR *pVal)

gets generated with this Java signature:

    public void GetBSTR(/*[out]*/ String[] p0) {

Furthermore, the tlb2java generated code expects you to pass an array of size one as the parameter to receive the output. Below are some example calls to GetBSTR. Notice, if you pass null to the method, you will receive a COM exception.

private void useDual(Dual dual) {
    String[] out_v = { null };
    dual.GetBSTR(out_v);
    System.out.println(out_v[0]);

    String[] out_v2 = new String[1];
    dual.GetBSTR(out_v);
    System.out.println(out_v[0]);

    try {
        dual.GetBSTR(null);
    } catch (COMException e) {
        assertEquals("The parameter is incorrect.", e.getMessage());
    }
}

$Id: call_out.html 3769 2007-06-08 19:06:43Z hastings $