
COM Object Return Multiple Arguments
Quote:
> Hi,
> I'm building an ATL com object and I need to find a way to
> return several parameters from the COM object into an ASP page.
> So far, no luck.
> does anybody know of a good way to return multiple arguments?
Your question is very vague...
By "multiple arguments" do you mean a variable number of arguments,
e.g. you need to pass an array back?
The easiest, and most common way of exposing data from INSIDE
the object to the consumer (ASP) is through properties, or
arguments in a method.
For example, let's say you had an ATL object that calculates
MPH based on a given distance (M) and a given time (H).
You would have a method something like this:
STDMETHODIMP CalculateMPH(VARIANT *Distance, VARIANT *ElapsedTime, VARIANT *MPH)
In here, you see that all variables are passed byref, so you don't have
to worry about [in] or [out] or [retval] or anything.
The caller, in ASP would do something like this:
<%
Dim oSpeed
Dim MPH, Hours, Miles
Miles = 60
Hours = 1
Set oSpeed = Server.CreateObject("MyObject.SpeedCalc") 'or whatever
oSpeed.CalculateMPH Miles, Hours, MPH
Response.Write MPH
%>
(the browser would then display 60)
Alternatively, you could have properties in your class, one for
Miles and one for Time and then one for MPH. The consumer (ASP)
would set the properties, then call CalculateMPH with no
arguments and the method would then read all the properties and
work with the data, then populate the MPH property for ASP
to get later.
-Chad