ComponentOne VSView 8.0
Handling ActiveX Optional Parameters in MFC

Optional parameters in COM interfaces are always of type VARIANT. To omit them in Visual Basic, you simply don't supply a value for them at all. The wrapper classes created by the MFC Wizard, however, require that you supply VARIANTS for all parameters, optional or not. In these cases, what you need to do is create a VARIANT of type VT_ERROR, and use that in place of the optional parameters.

For example, the VSPrinter control has a DrawLine X1,Y1,[X2,][Y2] method that takes two optional parameters. To invoke DrawLine omitting the optional parameters, you could write:

Example Title
Copy Code
COleVariant vNone(0L, VT_ERROR);

m_Printer.DrawLine(X1, Y1, vNone, vNone);

Notice that the VARIANT is created with a 0L value instead of simply 0. This is required by the compiler to resolve the ambiguity between the short and long types.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback