Q on var types in STDMETHODs 
Author Message
 Q on var types in STDMETHODs

I've basically adopted the rule of when doing interface methods/properties
only to use the types available in the VC wizard, but was wondering about
the (dis)advantages of using pointers with the [in] values.

For eg, if I have a property Item it could be

    HRESULT Item([in] VARIANT Index, [out, retval] IDispatch** pVal);

    HRESULT Item([in] VARIANT* Index, [out, retval] IDispatch** pVal);

OK, I can uderstand the [out, retval] has to be a pointer, but apart from a
little overhead saving, is there any gain in using VARIANT* for the [in]?
For eg will other programmers expect it if they use the library? Or do other
(client) languages need pointers - I presume VB just uses ByVal or ByRef
internally as needed to get nice syntax like Blahblah.Foos.Item(i)?

The reason I ask is a minor advantage for me using plain VARIANT is it makes
the calling code a little bit easier to use/read. I guess if it's
six-of-one, half-a-dozen-of-the-other, the main thing is to be consistent.

Thanks in advance from someone who knows just enough about this to get into
trouble :-)

David Bell



Wed, 23 Feb 2005 16:50:03 GMT  
 Q on var types in STDMETHODs
inline...



Quote:
> I've basically adopted the rule of when doing interface methods/properties
> only to use the types available in the VC wizard, but was wondering about
> the (dis)advantages of using pointers with the [in] values.

> For eg, if I have a property Item it could be

>     HRESULT Item([in] VARIANT Index, [out, retval] IDispatch** pVal);

>     HRESULT Item([in] VARIANT* Index, [out, retval] IDispatch** pVal);

> OK, I can uderstand the [out, retval] has to be a pointer, but apart from
a
> little overhead saving, is there any gain in using VARIANT* for the [in]?

Saves overhead? Only if there is no proxy-stub. If there is, the overhead is
probably slightly worse.

Quote:
> For eg will other programmers expect it if they use the library? Or do
other
> (client) languages need pointers - I presume VB just uses ByVal or ByRef
> internally as needed to get nice syntax like Blahblah.Foos.Item(i)?

> The reason I ask is a minor advantage for me using plain VARIANT is it
makes
> the calling code a little bit easier to use/read. I guess if it's
> six-of-one, half-a-dozen-of-the-other, the main thing is to be consistent.

IMHO, if I saw code that used the latter case, I would suspect the
programmer to be a novice, and I would be uncomfortable about using his
code.

Quote:
> Thanks in advance from someone who knows just enough about this to get
into
> trouble :-)

> David Bell



Thu, 24 Feb 2005 02:05:05 GMT  
 Q on var types in STDMETHODs
Thanks

Quote:

> >     HRESULT Item([in] VARIANT Index, [out, retval] IDispatch** pVal);

> >     HRESULT Item([in] VARIANT* Index, [out, retval] IDispatch** pVal);

> IMHO, if I saw code that used the latter case, I would suspect the
> programmer to be a novice, and I would be uncomfortable about using his
> code.

Because VARIANT* implies the value can be modified, which contradicts [in] ?

David Bell



Thu, 24 Feb 2005 05:30:35 GMT  
 Q on var types in STDMETHODs

Quote:

> I've basically adopted the rule of when doing interface methods/properties
> only to use the types available in the VC wizard, but was wondering about
> the (dis)advantages of using pointers with the [in] values.

> For eg, if I have a property Item it could be

>     HRESULT Item([in] VARIANT Index, [out, retval] IDispatch** pVal);

>     HRESULT Item([in] VARIANT* Index, [out, retval] IDispatch** pVal);

> OK, I can uderstand the [out, retval] has to be a pointer, but apart from a
> little overhead saving,

And it is only "a little" overhead savings.  VARIANT is, I think, only
16 bytes, compared to four for a pointer, and you won't typically have
all that many in an argument list.


Fri, 25 Feb 2005 22:03:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. type *var -- vs. -- type* var

2. Args: var number & var types

3. var type: (char (*)[256])

4. what does a (type **)var statement do?

5. Passing user defined type var between VB and VC

6. VC5.0 CDialog::OnOK() mangles type COleDateTime member var

7. Non-constant initializer for constant type var

8. CONFLICT - Global Var of a .LIB Vs Global Var of a program which uses the LIB

9. var = !var;

10. extern var vs. static extern var

11. Concatenate CString var + int var

12. How to change CString var into int var?

 

 
Powered by phpBB® Forum Software