SAMPLE: OPTARG: Optional parameters with Automation

Last reviewed: June 5, 1996
Article ID: Q131052
The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.03
  • Microsoft OLE libraries included with:

        - Microsoft Windows NT version 3.5
        - Microsoft Windows 95
    

SUMMARY

OPTARG is an OLE Automation server application that demonstrates automation methods with optional parameters and variable number of parameters. It implements an Add method that takes optional parameters and a Multiply method that takes a variable number of parameters.

See the README.TXT included with the sample for details to compile and run.

You can find OPTARG.EXE (size: 35703 bytes) 
                       , a self-extracting file, on these services:

  • Microsoft's World Wide Web site on the Internet

          On the www.microsoft.com home page, click the Support icon
          Click Knowledge Base, and select the product
    
          Enter kbfile OPTARG.EXE (size: 35703 bytes) 
                                 , and click GO!
          Open the article, and click the button to download the file
    
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the Softlib/Mslfiles folder
          Get OPTARG.EXE (size: 35703 bytes) 
    
  • The Microsoft Network

          On the Edit menu, click Go To, and then click Other Location
          Type "mssupport" (without the quotation marks)
          Double-click the MS Software Library icon
          Find the appropriate product area
          Locate and Download OPTARG.EXE
    
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download OPTARG.EXE (size: 35703 bytes) 
    

    For additional information about downloading, please see the following article in the Microsoft Knowledge Base:

       ARTICLE-ID: Q119591
       TITLE     : How to Obtain Microsoft Support Files from Online Services
    
    

    MORE INFORMATION

    Optional parameters are implemented by marking the parameter with the optional attribute and by using VARIANT as the type of the parameter. If the controller omits a parameter, the method will be passed a VARIANT with VARIANT.vt = VT_ERROR and VARIANT.scode = DISP_E_PARAMNOTFOUND.

    Variable parameters are implemented by marking the method with the vararg attribute and by providing a parameter of type SAFEARRAY(variant). This array will contain the variable number of parameters passed by the controller.

    Note that vararg methods do not have the upper limit of parameters that methods with optional parameters do.

    Because of a problem in the OLE dlls, invoking the Multiply method will cause an exception in the 32-bit OLE that shipped with Windows NT 3.5 and a GP fault in 16-bit OLE 2.02 and 2.03. This problem has been fixed in NT 3.51 and Windows 95.

    The problem occurs if a vararg method has a retval parameter. For example, the following will fail:

            [vararg]
            HRESULT Multiply([in] short RequiredInteger,
                          [in] SAFEARRAY(variant) VariableNumberOfIntegers,
                          [out, retval] long* retval);
    
    
    The problem does not occur if the vararg method doesn't have a retval parameter. For example, the following will currently work:

            [vararg]
            HRESULT Multiply([in] short RequiredInteger,
                          [in] SAFEARRAY(variant) VariableNumberOfIntegers);
    
            [vararg]
           long Multiply([in] short RequiredInteger,
                          [in] SAFEARRAY(variant) VariableNumberOfIntegers);
    

  • Additional reference words: arguments 3.50 4.00
    KBCategory: kbfile
    KBSubcategory: LeTwoAt


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: June 5, 1996
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.