I am trying to call ActiveX function which resides on a client computer from javascript or vbscript. 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.
Javascript 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 javascript follows. Thanks for any kind of help.
<HTML>
<HEAD>
<OBJECT classid=”A2733628-A334-4207-83F1-F00198758EFF” id=”a”></OBJECT>
<TITLE></TITLE>
<script type=’text/javascript’ language=’javascript’>
function callTest()
{
//first way
try{
var myobject;
myobject = new ActiveXObject(“OCXTEST.ocxtestCtrl.1”);
alert(myobject.test()); // activex method is called test
}
catch(e)
{
alert(e.message);
}
//second way
try{
alert(a.test());
}
catch(e)
{
alert(e.message);
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE=”button” value=”TEST” onClick=”callTest()”>
</BODY>
</HTML>