I am trying to call ActiveX function which resides on a client
computer from vbscript or javascript. I developed a simple Visual C++
2005 ActiveX component (ocx file) with one exported method which
returns int value. When I try to call this method from VB, everything
works fine and I get the value that method should return.

The ActiveX component was registered on the client computer with
regsvr32. I tried in two ways to call the ocx method from javascript:
- with new ActiveXObject("progID"), where the progID was found in the
registry,
- with <object classid="clsid:xxxxxxx" id="xx">, and classid was also
found in the registry.

VBscript makes the object, but cannot call the ocx method. An error
"Object doesn't support this property or method" appears on the web
page.

At Internet Explorer options I enabled all activex objects both in
Internet and intranet zone.

I looked for some kind of solution everywhere, but didn't succeed. I
am blocked at two lines of code for a week. The code of html page with
vbscript follows. Thanks for any kind of help.

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT language="vbscript">
Sub callTest
document.write(a.test())
End Sub
</SCRIPT>
</HEAD>
<BODY>
<OBJECT id="a" classid="CLSID:A2733628-A334-4207-83F1-F00198758EFF"
name="a" ></OBJECT>
<INPUT TYPE=button value="Test" onClick="callTest">
</BODY>
</HTML>

Re: Cannot call ActiveX component function from VBScript by Tom

Tom
Wed Sep 05 07:12:28 PDT 2007

On Sep 5, 4:30 am, mer...@gmail.com wrote:
> I am trying to call ActiveX function which resides on a client
> computer from vbscript or javascript. I developed a simple Visual C++
> 2005 ActiveX component (ocx file) with one exported method which
> returns int value. When I try to call this method from VB, everything
> works fine and I get the value that method should return.
>
> The ActiveX component was registered on the client computer with
> regsvr32. I tried in two ways to call the ocx method from javascript:
> - with new ActiveXObject("progID"), where the progID was found in the
> registry,
> - with <object classid="clsid:xxxxxxx" id="xx">, and classid was also
> found in the registry.
>
> VBscript makes the object, but cannot call the ocx method. An error
> "Object doesn't support this property or method" appears on the web
> page.
>
> At Internet Explorer options I enabled all activex objects both in
> Internet and intranet zone.
>
> I looked for some kind of solution everywhere, but didn't succeed. I
> am blocked at two lines of code for a week. The code of html page with
> vbscript follows. Thanks for any kind of help.
>
> <HTML>
> <HEAD>
> <TITLE></TITLE>
> <SCRIPT language="vbscript">
> Sub callTest
> document.write(a.test())
> End Sub
> </SCRIPT>
> </HEAD>
> <BODY>
> <OBJECT id="a" classid="CLSID:A2733628-A334-4207-83F1-F00198758EFF"
> name="a" ></OBJECT>
> <INPUT TYPE=button value="Test" onClick="callTest">
> </BODY>
> </HTML>

I am not an expert in this stuff, but I have seen similar problems
discussed here in the past. I believe it is a variable typing
problem. Scripting only supports the Variant variable type. Your
object must return a variable of type variant. It can be subtyped
integer, but must be a variant to be accessible from script.

I have also seen problems with security because not all ActiveX
objects are marked safe for scripting, but that doesn't seem to be the
issue here.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


Re: Cannot call ActiveX component function from VBScript by mayayana

mayayana
Wed Sep 05 07:49:19 PDT 2007


I tried your code with another control, returning
a property. (I didn't have a function with no parameters
to test.) It worked with:

document.write(a.test)

but caused an error with:

document.write(a.test())

Another point, as Tom Lavedas said, is that an integer
type is not supported in VBS. You should return a
variant.

Neither of those seems to explain your error, though.
The code you have should work. Your error is indicating
that the function name is not in the component's type
library. Two thoughts on that, which may or may not
help:

1) Check your component in an object browser to make
sure you have a function named "test".

2) I've noticed that sometimes using RegSvr the
HKCR\Typelib key does not get updated and can cause
the error you're describing. It seems to happen when
a component is recompiled without changing the GUIDs.
(I don't know why. I suspect it's because the version
number doesn't get changed in the HKCR\Typelib subkeys.
But that's just a guess.)

So if you registered the component before you added
"test" and then re-registered it, that could explain the
problem. In that case you'd probably need to go in and fix
it by hand or recompile with new GUIDs.

> I am trying to call ActiveX function which resides on a client
> computer from vbscript or javascript. I developed a simple Visual C++
> 2005 ActiveX component (ocx file) with one exported method which
> returns int value. When I try to call this method from VB, everything
> works fine and I get the value that method should return.
>
> The ActiveX component was registered on the client computer with
> regsvr32. I tried in two ways to call the ocx method from javascript:
> - with new ActiveXObject("progID"), where the progID was found in the
> registry,
> - with <object classid="clsid:xxxxxxx" id="xx">, and classid was also
> found in the registry.
>
> VBscript makes the object, but cannot call the ocx method. An error
> "Object doesn't support this property or method" appears on the web
> page.
>
> At Internet Explorer options I enabled all activex objects both in
> Internet and intranet zone.
>
> I looked for some kind of solution everywhere, but didn't succeed. I
> am blocked at two lines of code for a week. The code of html page with
> vbscript follows. Thanks for any kind of help.
>
> <HTML>
> <HEAD>
> <TITLE></TITLE>
> <SCRIPT language="vbscript">
> Sub callTest
> document.write(a.test())
> End Sub
> </SCRIPT>
> </HEAD>
> <BODY>
> <OBJECT id="a" classid="CLSID:A2733628-A334-4207-83F1-F00198758EFF"
> name="a" ></OBJECT>
> <INPUT TYPE=button value="Test" onClick="callTest">
> </BODY>
> </HTML>
>



Re: Cannot call ActiveX component function from VBScript by Richard

Richard
Wed Sep 05 09:40:59 PDT 2007


<merdza@gmail.com> wrote in message
news:1188981002.879009.310930@y42g2000hsy.googlegroups.com...
>I am trying to call ActiveX function which resides on a client
> computer from vbscript or javascript. I developed a simple Visual C++
> 2005 ActiveX component (ocx file) with one exported method which
> returns int value. When I try to call this method from VB, everything
> works fine and I get the value that method should return.
>
> The ActiveX component was registered on the client computer with
> regsvr32. I tried in two ways to call the ocx method from javascript:
> - with new ActiveXObject("progID"), where the progID was found in the
> registry,
> - with <object classid="clsid:xxxxxxx" id="xx">, and classid was also
> found in the registry.
>
> VBscript makes the object, but cannot call the ocx method. An error
> "Object doesn't support this property or method" appears on the web
> page.
>
> At Internet Explorer options I enabled all activex objects both in
> Internet and intranet zone.
>
> I looked for some kind of solution everywhere, but didn't succeed. I
> am blocked at two lines of code for a week. The code of html page with
> vbscript follows. Thanks for any kind of help.
>
> <HTML>
> <HEAD>
> <TITLE></TITLE>
> <SCRIPT language="vbscript">
> Sub callTest
> document.write(a.test())
> End Sub
> </SCRIPT>
> </HEAD>
> <BODY>
> <OBJECT id="a" classid="CLSID:A2733628-A334-4207-83F1-F00198758EFF"
> name="a" ></OBJECT>
> <INPUT TYPE=button value="Test" onClick="callTest">
> </BODY>
> </HTML>
>

I've compiled ocx ActiveX components in VB with public functions that return
integers (integer, long, boolean, string, and variant) and they work fine
when called from VBScript. Are you sure the method you call was declared
Public? Are methods Private by default?

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Cannot call ActiveX component function from VBScript by mr_unreliable

mr_unreliable
Wed Sep 05 09:46:46 PDT 2007

merdza@gmail.com wrote:
> I am trying to call ActiveX function which resides on a client
> computer from vbscript or javascript. I developed a simple Visual C++
> 2005 ActiveX component (ocx file) with one exported method which
> returns int value. When I try to call this method from VB, everything
> works fine and I get the value that method should return.
>
hi Merdza,

As has been already mentioned above, vbscript is happiest when
you program gets/puts values as variants. But there is something
else going on too. This is referred to as "coercion". In other
words, in many if not most cases, vbScript will coerce the
value provided into a variant, and of the right type (gasp!).

Don't ask me to explain how coersion works, but it does.

There is another issue, apparently not mentioned already. That
is the "IUnknown" vs. the "IDispatch" interfaces. Either one
will work with most languages, but one (IUnknown, I think) is
the one preferred by vbScript when interfacing with an object.
I think it is "IUnknown" that allows vbscript to figure out
what methods and properties are available _without_ a typelib.
At any rate, (if my memory serves), any object coded (in c++)
for use by vbScrpt should use the IUnknown interface.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


Re: Cannot call ActiveX component function from VBScript by mayayana

mayayana
Wed Sep 05 12:46:27 PDT 2007

> There is another issue, apparently not mentioned already. That
> is the "IUnknown" vs. the "IDispatch" interfaces. Either one
> will work with most languages, but one (IUnknown, I think) is
> the one preferred by vbScript when interfacing with an object.

I think maybe you mean binding? Any COM object
has to have an IUnknown interface. Then it also needs
an IDispatch interface if it's going to support late
binding which is what script can handle. IDispatch provides
the methods to find the address of functions
in the virtual function table (vtable), as opposed to
"early binding" which can be used to compile the vtable
addresses directly into an executable and thereby
avoid the overhead of asking the object for the addresses
of its functions at runtime.



thanks for the clarification... by mr_unreliable

mr_unreliable
Thu Sep 06 10:01:13 PDT 2007

You say vbScript is needing _BOTH_ interfaces.

Then that's what the O.P. needs to check for
-- that both interfaces have been coded into
his-or-her own actx object.

cheers, jw

p.s. Thank goodness vb takes care of all this...

mayayana wrote:
> I think maybe you mean binding? Any COM object
> has to have an IUnknown interface. Then it also needs
> an IDispatch interface if it's going to support late
> binding which is what script can handle.

Re: thanks for the clarification... by merdza

merdza
Fri Sep 07 06:22:52 PDT 2007

I have solved the problem!!!

The problem wasn't at all in vbscript, but in ocx file as I assumed
later.

Methods cannot be exported from ActiveX control like I did in Win32
project dll. Then, I exported them through .def file, or with
__declspec(dllexport).

In MFC ActiveX project, the methods become visible to other
applications by so called dispatch map. The best thing to do is to add
such methods through wizard, and then Visual Studio declares them in
various files as methods that should be exported.