Microsoft KB Archive/238981

= How to pass optional parameters when you call a function in Visual C++ =

Article ID: 238981

Article Last Modified on 9/1/2005

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q238981



SUMMARY
When you call a method that has optional parameters from Visual C++, you cannot omit the optional parameters. You need to pass a special VARIANT instead.



MORE INFORMATION
Some methods have "optional" parameters. In Visual Basic, you can omit them when calling the method. However, when calling with Visual C++, you have to pass a special VARIANT whose .vt field has the value VT_ERROR and .scode field has the value DISP_E_PARAMNOTFOUND. That is: // VARIANT used in place of optional-parameters. VARIANT varOpt; varOpt.vt = VT_ERROR; varOpt.scode = DISP_E_PARAMNOTFOUND; This is what Visual Basic is doing behind-the-scenes.

Keywords: kbhowto kbfaq KB238981

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.