parameter?? 
Author Message
 parameter??

Hi all,
this is really stupid but this question is in mind since
very begining. I have a method in idl file like.

HRESULT DoSomething([in]long  p1, [in, optional]long p2);

the declaration of same in the CoClass is like..

HRESULT DoSomething(long  p1, long p2 = 10 );

I  know that i can put the def value in [defaultvalue]
attribute in IDL.
 But in this case though it is working fine is it the
correct COM programming. I mean can it go wrong someweher
due to above kind of declaration of default value in Class.
thanks in advance
Nitin



Sun, 23 May 2004 00:03:03 GMT  
 parameter??
Does MIDL compile this? The documentation says "The [optional] attribute is
valid only if the parameter is of type VARIANT or VARIANT *."

C++ default arguments are processed at compile time and have meaning only to
C++ compiler. The information is lost in the compiled code. There is no way
for a client, or a stub, or IDispatch implementation (whoever ends up
calling your method) to learn that you expect 10 when an argument is
missing, unless this information is stored in the TLB, which is exactly what
[defaultvalue] attribute achieves.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat, and
wrong." H.L. Mencken


Quote:
> Hi all,
> this is really stupid but this question is in mind since
> very begining. I have a method in idl file like.

> HRESULT DoSomething([in]long  p1, [in, optional]long p2);

> the declaration of same in the CoClass is like..

> HRESULT DoSomething(long  p1, long p2 = 10 );

> I  know that i can put the def value in [defaultvalue]
> attribute in IDL.
>  But in this case though it is working fine is it the
> correct COM programming. I mean can it go wrong someweher
> due to above kind of declaration of default value in Class.
> thanks in advance
> Nitin



Sun, 23 May 2004 00:28:15 GMT  
 parameter??
Can I throw a couple more questions on this one?

I'd like to be able to have a COM function with the following signature
    function MyMethod(Optional arg1 = enumValue) as Object

Now I seem to have gotten away with ( [in,optional, defaultvalue(enumValue)]
arg1, IObject** pp )

but all reference material on this says:
    1. defaultvalue can not be used with optional
    2. defaultvaule must appear after all args

My method seems to work in VB/C++ and looks exactly how I want it - will
this bite me later on?
Am I actually breaking rule 2 even though the last argument is really a
return value?

Joe


Quote:
> Does MIDL compile this? The documentation says "The [optional] attribute
is
> valid only if the parameter is of type VARIANT or VARIANT *."

> C++ default arguments are processed at compile time and have meaning only
to
> C++ compiler. The information is lost in the compiled code. There is no
way
> for a client, or a stub, or IDispatch implementation (whoever ends up
> calling your method) to learn that you expect 10 when an argument is
> missing, unless this information is stored in the TLB, which is exactly
what
> [defaultvalue] attribute achieves.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat, and
> wrong." H.L. Mencken



> > Hi all,
> > this is really stupid but this question is in mind since
> > very begining. I have a method in idl file like.

> > HRESULT DoSomething([in]long  p1, [in, optional]long p2);

> > the declaration of same in the CoClass is like..

> > HRESULT DoSomething(long  p1, long p2 = 10 );

> > I  know that i can put the def value in [defaultvalue]
> > attribute in IDL.
> >  But in this case though it is working fine is it the
> > correct COM programming. I mean can it go wrong someweher
> > due to above kind of declaration of default value in Class.
> > thanks in advance
> > Nitin



Sun, 23 May 2004 03:25:01 GMT  
 parameter??
yes MIDL compiles it.
popsy

Quote:
>-----Original Message-----
>Does MIDL compile this? The documentation says "The

[optional] attribute is
Quote:
>valid only if the parameter is of type VARIANT or VARIANT
*."

>C++ default arguments are processed at compile time and

have meaning only to
Quote:
>C++ compiler. The information is lost in the compiled

code. There is no way
Quote:
>for a client, or a stub, or IDispatch implementation
(whoever ends up
>calling your method) to learn that you expect 10 when an
argument is
>missing, unless this information is stored in the TLB,

which is exactly what
Quote:
>[defaultvalue] attribute achieves.
>--
>With best wishes,
>    Igor Tandetnik

>"For every complex problem, there is a solution that is
simple, neat, and
>wrong." H.L. Mencken



>> Hi all,
>> this is really stupid but this question is in mind since
>> very begining. I have a method in idl file like.

>> HRESULT DoSomething([in]long  p1, [in, optional]long
p2);

>> the declaration of same in the CoClass is like..

>> HRESULT DoSomething(long  p1, long p2 = 10 );

>> I  know that i can put the def value in [defaultvalue]
>> attribute in IDL.
>>  But in this case though it is working fine is it the
>> correct COM programming. I mean can it go wrong
someweher
>> due to above kind of declaration of default value in
Class.
>> thanks in advance

>.



Sun, 23 May 2004 03:59:35 GMT  
 parameter??
[defaultvalue] implies [optional]. [retval] is allowed after [optional] or
[defaultvalue]. Your IDL definition should be

HRESULT MyMethod([in, defaultvalue(enumValue)] long arg1, [out, retval]
IObject **pp);

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat, and
wrong." H.L. Mencken


Quote:
> Can I throw a couple more questions on this one?

> I'd like to be able to have a COM function with the following signature
>     function MyMethod(Optional arg1 = enumValue) as Object

> Now I seem to have gotten away with ( [in,optional,

defaultvalue(enumValue)]
Quote:
> arg1, IObject** pp )

> but all reference material on this says:
>     1. defaultvalue can not be used with optional
>     2. defaultvaule must appear after all args

> My method seems to work in VB/C++ and looks exactly how I want it - will
> this bite me later on?
> Am I actually breaking rule 2 even though the last argument is really a
> return value?

> Joe



> > Does MIDL compile this? The documentation says "The [optional] attribute
> is
> > valid only if the parameter is of type VARIANT or VARIANT *."

> > C++ default arguments are processed at compile time and have meaning
only
> to
> > C++ compiler. The information is lost in the compiled code. There is no
> way
> > for a client, or a stub, or IDispatch implementation (whoever ends up
> > calling your method) to learn that you expect 10 when an argument is
> > missing, unless this information is stored in the TLB, which is exactly
> what
> > [defaultvalue] attribute achieves.
> > --
> > With best wishes,
> >     Igor Tandetnik

> > "For every complex problem, there is a solution that is simple, neat,
and
> > wrong." H.L. Mencken



> > > Hi all,
> > > this is really stupid but this question is in mind since
> > > very begining. I have a method in idl file like.

> > > HRESULT DoSomething([in]long  p1, [in, optional]long p2);

> > > the declaration of same in the CoClass is like..

> > > HRESULT DoSomething(long  p1, long p2 = 10 );

> > > I  know that i can put the def value in [defaultvalue]
> > > attribute in IDL.
> > >  But in this case though it is working fine is it the
> > > correct COM programming. I mean can it go wrong someweher
> > > due to above kind of declaration of default value in Class.
> > > thanks in advance
> > > Nitin



Sun, 23 May 2004 04:08:05 GMT  
 parameter??
it works but you need to do the following (it's kind of non-COM standard)
[in, defaultvalue(-2)] int iMyNum

or [in, optional] VARIANT <- this is allowed for an automation interface

--
Egbert Nierop

Session management for webfarms:
http://www.nieropwebconsult.nl/asp_session_manager.htm


Quote:
> Hi all,
> this is really stupid but this question is in mind since
> very begining. I have a method in idl file like.

> HRESULT DoSomething([in]long  p1, [in, optional]long p2);

> the declaration of same in the CoClass is like..

> HRESULT DoSomething(long  p1, long p2 = 10 );

> I  know that i can put the def value in [defaultvalue]
> attribute in IDL.
>  But in this case though it is working fine is it the
> correct COM programming. I mean can it go wrong someweher
> due to above kind of declaration of default value in Class.
> thanks in advance
> Nitin



Wed, 26 May 2004 01:29:59 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. VC7 does NOT support template-template parameters involving non-type parameters

2. function parameters: default value, optional parameter

3. pCmd->Parameters->Count fails when there's no parameter

4. Parsing application parameters(command line parameters)

5. Input parameters and Output parameters

6. functors and for_each. operator() after: binding n-1 parameters vs constructor having n-1 parameters

7. ASCII conversion of string parameter in passing parameter from eVB app to eVC DLL?????

8. How do you declare optiona method parameters in C#

9. C# equivalent of C++ const method parameter?

10. Parameter Information

11. question to events with out parameters

12. Crystal Reports - Parameters runtime customization

 

 
Powered by phpBB® Forum Software