It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Calling ActiveX method from JavaScript problem

Calling ActiveX method from JavaScript problem

Postby Pera Pisar on Wed Sep 05, 2007 9:19 am

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>
Pera Pisar
 
Posts: 2
Joined: Wed Sep 05, 2007 8:41 am

Postby Pera Pisar on Fri Sep 07, 2007 12:52 pm

I have solved the problem!!!

The problem wasn't at all in javascript, 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.
Pera Pisar
 
Posts: 2
Joined: Wed Sep 05, 2007 8:41 am


Who is online

Users browsing this forum: No registered users and 3 guests