Hi
I am trying to invoke a COM object through a script. When
the script is executed we neither get the return value nor
the error. But the COM interface documentation specifies
that the COM Object interface returns a string as an
output.

I had posted this question earlier but the I had written
the code in Jscript now I tried the invokation with the
VBscript. Now I am getting a run time error saying "type
mismatch".

Here is the COM interface specification provided by the
vendor.

HRESULT Schedule ([in] BSTR xmlDataSource,
[in] BSTR xmlSchedule,
[out] BSTR xmlScheduleResult;
[out] BSTR xmlReturn);

to invoke this interface we are using the code below

Set obj = WScript.CreateObject("LSANAL.Analysis")
Dim third, value, result

arg0 = "ACCOUNT"
arg1 = "Test"

result=obj.Schedule(arg0,arg1,third,value);

WScript.echo(third);
WScript.echo(value);

Could you please let me know what might be wrong or what
could I do to get the output?

Thank you,
VinodRamu
..

Re: Error invoking COM Object by Oisin

Oisin
Thu Jul 17 12:24:27 CDT 2003

IIRC, VBScript/JScript can only handle Variant in/out types. You need to use
VB6 for this one. Either write a wrapper COM object in VB that uses variants
and access this through script, or use VB6 outright instead of script.

Hope this helps,

- Oisin



"VinodRamu" <vinod.ramu@wipro.com> wrote in message
news:00af01c34c84$bf9c2020$a401280a@phx.gbl...
> Hi
> I am trying to invoke a COM object through a script. When
> the script is executed we neither get the return value nor
> the error. But the COM interface documentation specifies
> that the COM Object interface returns a string as an
> output.
>
> I had posted this question earlier but the I had written
> the code in Jscript now I tried the invokation with the
> VBscript. Now I am getting a run time error saying "type
> mismatch".
>
> Here is the COM interface specification provided by the
> vendor.
>
> HRESULT Schedule ([in] BSTR xmlDataSource,
> [in] BSTR xmlSchedule,
> [out] BSTR xmlScheduleResult;
> [out] BSTR xmlReturn);
>
> to invoke this interface we are using the code below
>
> Set obj = WScript.CreateObject("LSANAL.Analysis")
> Dim third, value, result
>
> arg0 = "ACCOUNT"
> arg1 = "Test"
>
> result=obj.Schedule(arg0,arg1,third,value);
>
> WScript.echo(third);
> WScript.echo(value);
>
> Could you please let me know what might be wrong or what
> could I do to get the output?
>
> Thank you,
> VinodRamu
> ..
>
>



Re: Error invoking COM Object by Mark_Pryor

Mark_Pryor
Thu Jul 17 12:27:04 CDT 2003

Hello
"VinodRamu" <vinod.ramu@wipro.com> wrote in message
news:00af01c34c84$bf9c2020$a401280a@phx.gbl...
> Hi
> I am trying to invoke a COM object through a script. When
> the script is executed we neither get the return value nor
> the error. But the COM interface documentation specifies
> that the COM Object interface returns a string as an
> output.
>
> I had posted this question earlier but the I had written
> the code in Jscript now I tried the invokation with the
> VBscript. Now I am getting a run time error saying "type
> mismatch".
>
> Here is the COM interface specification provided by the
> vendor.
>
> HRESULT Schedule ([in] BSTR xmlDataSource,
> [in] BSTR xmlSchedule,
> [out] BSTR xmlScheduleResult;
> [out] BSTR xmlReturn);
>
> to invoke this interface we are using the code below
>
> Set obj = WScript.CreateObject("LSANAL.Analysis")
> Dim third, value, result
>
> arg0 = "ACCOUNT"
> arg1 = "Test"
>
> result=obj.Schedule(arg0,arg1,third,value);
>
> WScript.echo(third);
> WScript.echo(value);
>
> Could you please let me know what might be wrong or what
> could I do to get the output?

Open the vendor's object in OLEView. I doubt that the
return value will show as HRESULT. If this is a Subroutine
then you will see VOID as the return. If it shows return
type: long or VARIANT_bool, then you might have a problem.

If it shows VOID then remove result=

hth,
Mark Pryor

>
> Thank you,
> VinodRamu
> ..
>
>



Re: Error invoking COM Object by Michael

Michael
Thu Jul 17 21:17:21 CDT 2003

VinodRamu wrote:
> Hi
> I am trying to invoke a COM object through a script. When
> the script is executed we neither get the return value nor
> the error. But the COM interface documentation specifies
> that the COM Object interface returns a string as an
> output.
>
> I had posted this question earlier but the I had written
> the code in Jscript ...

Given the IDL, this will never work in JScript (COM version, not .NET
version) since JScript doesn't support [out] or [in,out] (by reference)
parameters, only [out,retval] (a function return value)...

> ...now I tried the invokation with the
> VBscript. Now I am getting a run time error saying "type
> mismatch".
>
> Here is the COM interface specification provided by the
> vendor.
>
> HRESULT Schedule ([in] BSTR xmlDataSource,
> [in] BSTR xmlSchedule,
> [out] BSTR xmlScheduleResult;
> [out] BSTR xmlReturn);

This is not a function that returns a value. The IDL for a return value is
[out,retval].

>
> to invoke this interface we are using the code below
>
> Set obj = WScript.CreateObject("LSANAL.Analysis")
> Dim third, value, result
>
> arg0 = "ACCOUNT"
> arg1 = "Test"
>
> result=obj.Schedule(arg0,arg1,third,value);

You are also mixing JScript syntax in VBScript - lose all the ;'s ...

Call obj.Schedule(arg0,arg1,third,value)
or
obj.Schedule arg0,arg1,third,value


>
> WScript.echo(third);
> WScript.echo(value);

WScript.echo third
WScript.echo value
>
> Could you please let me know what might be wrong or what
> could I do to get the output?
>
> Thank you,
> VinodRamu
> ..

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp


Re: Error invoking COM Object by Oisin

Oisin
Fri Jul 18 05:05:32 CDT 2003

MORE INFORMATION
VBScript only supports VARIANT ByRef parameters. You can use VBScript to
call a procedure that takes ByRef strings, but the default behavior of
components built with Visual Basic is to fail with a type mismatch error
when trying to pass ByRef parameters to these components. OLE Automation's
default type-coercion function fails when asked to convert a ByRef variant
into any other ByRef type.

VBScript does not impose this restriction. However, it is the default
behavior of the component that decides that a ByRef variant cannot be
converted into a ByRef string.

If a parameter to a procedure is enclosed in parenthesis, the parameter is
first evaluated as an expression. Because the result of an expression cannot
be passed by reference, the parameter is passed ByVal and no error is
reported.

Avoid using ByRef parameters unless they are explicitly needed. This is
because:
a.. ByRef procedures cause more overhead during cross-process marshaling,
because COM must marshal the value both to and from the object. ByVal
parameters require only one-way marshaling.

However, if you are willing to accept the overhead of any marshaling at
all, an extra parameter marshal back is unlikely to cause a huge performance
degradation.
b.. ByRef parameters can introduce hard-to-find bugs in your code if you
accidentally change the value of one of the parameters.
c.. JScript does not support ByRef parameters of any type, so if you plan
to write components that will support JScript, you should not use ByRef
parameters at all.
REFERENCES
For additional information, click the article numbers below to view the
articles in the Microsoft Knowledge Base:
197957 PRB: Passing Parameters by Reference to a VC COM Object

197956 PRB: Passing Parameters by Reference to a VB COM Object

174576 HOWTO: Returning Arrays from Server-Side Objects in ASP

218454 HOWTO: Implement Array Arguments in VC COM Objects for Active Server
Pages

217114 HOWTO: Implement Array Arguments in Visual Basic COM Objects for
Active Server Pages


"Avijit" <msdn-user-13@wildpackets.com> wrote in message
news:%23suKR7KTDHA.2196@TK2MSFTNGP12.phx.gbl...
> I doubt that the problem is with BSTRs. The VBScript runtime should have
no
> trouble to convert the BSTR to Variant.
>
> I think the problem is with passing by value/ref? But I am not an expert
in
> this area and will appreciate a proper response.