Solved

Default parameters for ActiveX controls.

Posted on 1998-12-10
5
215 Views
Last Modified: 2013-11-20
Is it possible to define default settings for ActiveX methods in VC++6.0? Something like in C++:

void NewItem(int size, int type = 0);
0
Comment
Question by:sdj
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1325983
I don't think you can do this.

I don't think you can overload methods with the same name and different parameter lists either.

Presumably this is because COM is supposed to be language independant, and this would not be allowable in some languages.

Why not simply define 2 methods

void NewItem( int size )

and

void NewItem2( int size, int type )


Both functions can use the same code (e.g. NewItem, calls NewItem2 with type = 0, or both calling some underlying internal function to do the work ).
0
 

Author Comment

by:sdj
ID: 1325984
Not a very user friendly approach. But I here what you are saying.
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1325985
You can have optional arguments. However, you need to write the function method yourself. You can use the optional keyword in the IDL file to specify that the argument to the function is optional. The argument type must be either VARIANT or VARIANT*.

However, to implement default arguments, you need to check for VT_EMPTY in that argument and supply your own default.


0
 

Author Comment

by:sdj
ID: 1325986
Any chance of a sample, or a pointer to where I may find some useful code?
0
 
LVL 1

Expert Comment

by:gvg
ID: 1325987
The ODL file would have a line like this.

[id(2)] long increase( long value, [optional] VARIANT incVal )

Then you would have a function like this

long increase( long value, VARIANT incVal )
{
  VARIANT varCon;
 
  // Init a the new variant.
  ::VariantInit(&varCon);

  // Try to convert the incoming variant to I4 ( 4 byte integer )
  if (S_OK = ::VariantChangeType(&varCon, &incVal, 0, VT_I4 );
    return value + varCon.lVal;
  else
    return value + 1;
}

If you use VB to call this function you only have to give one paramter and VB will take care of the rest.  If how ever you use vc++ you must pass both arguments and you must make sure that the vvariant you pass is VT_EMPTY if you would like to use default behavior.  All you need to do to create an empty variant is

VARIANT emptyVar;
VariantInit( &emptyVar );

VariantInit sets the variant type to empty.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 96
Strange date stored 22 148
how do i create updater to My Activex application? 3 94
dog bark java program 15 105
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question