• A TypeLib and 'defaultvalue' problem - only at the end ?

    From R.Wieser@21:1/5 to All on Mon Jan 18 09:59:11 2021
    Hello all,

    In a typelib (.IDL file) I'm trying to define a method with default values
    for some arguments:

    HRESULT MyMethod([in] variant* Arg1, [in, defaultvalue(-1)] long Arg2, [in] long Arg3, [in] variant* Arg4, [in, defaultvalue(-1)] long Arg5, [in]
    variant* Arg6, [out, retval] variant* TheResult);

    From VBScript I'm trying to call the method without specifying those "defaultvalue" arguments

    TheResult = MyMethod(Arg1,,Arg3,Arg4,,Arg6)

    Alas, I'm getting an error saying that the (Arg2 and Arg5) arguments are not optional.

    My question: How come ? Those "defaultvalue" arguments locations are, AFAICS, known and fixed. What do I need to also specify to make the above
    work ?

    Remark: using a one or more "defaultvalue" arguments at the end of a method (before the "retval" one) works fine.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Mon Jan 18 18:11:22 2021
    On Mon, 18 Jan 2021 09:59:11 +0100, R.Wieser wrote:
    Hello all,

    In a typelib (.IDL file) I'm trying to define a method with default values for some arguments:

    HRESULT MyMethod([in] variant* Arg1, [in, defaultvalue(-1)] long Arg2, [in] long Arg3, [in] variant* Arg4, [in, defaultvalue(-1)] long Arg5, [in] variant* Arg6, [out, retval] variant* TheResult);

    From VBScript I'm trying to call the method without specifying those "defaultvalue" arguments

    TheResult = MyMethod(Arg1,,Arg3,Arg4,,Arg6)

    Alas, I'm getting an error saying that the (Arg2 and Arg5) arguments are not optional.

    My question: How come ? Those "defaultvalue" arguments locations are, AFAICS, known and fixed. What do I need to also specify to make the above work ?

    Remark: using a one or more "defaultvalue" arguments at the end of a method (before the "retval" one) works fine.

    Regards,
    Rudy Wieser

    The `defaultvalue` attribute requires the `optional` attribute.

    HRESULT Func([in, optional, defaultvalue("something")] BSTR Text);

    The remarks for both attributes in MSDN describe what are accepted by MIDL.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Mon Jan 18 13:03:20 2021
    JJ,

    The `defaultvalue` attribute requires the `optional` attribute.

    I'm going to read that as "if not used at the end than ...".

    But alas, when I try I get an "invalid attribute combination" ... (my
    TypeLib compiler is 'mktyplib' which is .. a bit old - as old as the rest of
    my Borland Assembler)

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Tue Jan 19 12:17:06 2021
    On Mon, 18 Jan 2021 13:03:20 +0100, R.Wieser wrote:
    JJ,

    The `defaultvalue` attribute requires the `optional` attribute.

    I'm going to read that as "if not used at the end than ...".

    But alas, when I try I get an "invalid attribute combination" ... (my
    TypeLib compiler is 'mktyplib' which is .. a bit old - as old as the rest of my Borland Assembler)

    Regards,
    Rudy Wieser

    MIDL is available in all Windows SDK versions for NT based Windows. But I recommend at least Windows SDK for Vista if you don't have any standalone Windows SDK yet. It's a big 1.2GB ISO download, but it's worth it.

    https://www.microsoft.com/en-us/download/details.aspx?id=14477

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)