Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Default parameters for ActiveX controls.

Posted on 1998-12-10
5
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 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