Solved

Default parameters for ActiveX controls.

Posted on 1998-12-10
5
210 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now