Pass parameter by Reference in COM interface 
Author Message
 Pass parameter by Reference in COM interface

Hi All,

I have a method in a COM class as following: (COM will be running in
MTS environment)

Public Function InsertMedicalEnroll(ByVal strSSN As Variant,
aMedicalRec() As Variant) As Long
    Coding here..
End function

Someone said that is no good to pass parameter by reference in COM
interface.  Should I must pass any parameter by value in any public
function of COM? If so, if I need to pass array argument, it will be
problem.

Any suggestion and thought?

TIA,

Yin



Tue, 30 Dec 2003 01:47:51 GMT  
 Pass parameter by Reference in COM interface
Passing parameters by value reduces the amount of time spent marshaling them
back and forth. Generally you should stick with ByVal but for some data
types such as Arrays and UDTs you must use ByRef. Try wrapping your array
into a Variant and send it by value.

However, if you are calling methods on classes in the same process then
ByRef will be faster in some cases, since the compiler will not be making
multiple copies of value types, but it will rather use the pointer to the
same data. As soon as you start dealing with components in remote locations,
esp. MTS and COM+, ByVal is a better choice.

--
Sanin Saracevic, MCP
Lead Software Architect
Interland, Inc.


Quote:
> Hi All,

> I have a method in a COM class as following: (COM will be running in
> MTS environment)

> Public Function InsertMedicalEnroll(ByVal strSSN As Variant,
> aMedicalRec() As Variant) As Long
>     Coding here..
> End function

> Someone said that is no good to pass parameter by reference in COM
> interface.  Should I must pass any parameter by value in any public
> function of COM? If so, if I need to pass array argument, it will be
> problem.

> Any suggestion and thought?

> TIA,

> Yin



Tue, 30 Dec 2003 02:38:24 GMT  
 Pass parameter by Reference in COM interface
Hi Mr071,

can you explain me or point me to some documentation explainig why Arrays
and UDTs have to be passed ByRef?

Thanks.



Fri, 02 Jan 2004 03:58:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. define COM interface when the the number of parameters may be changed

2. Passing COM interface pointers in VB

3. How to pass NULL for interface pointer parameter?

4. HELP: Are COM function parameters copied or referenced?

5. Parameter passing by reference between C++ and VBScript

6. passing active x control reference to com.dll created in java

7. Question: passing parameters by reference

8. Problems with passing parameters by reference to a sub program

9. Passing by reference to an ATL COM component

10. Passing a variable by reference in a COM object

11. Can I pass parameters by reference?

12. Pass a reference to a COM object

 

 
Powered by phpBB® Forum Software