/    Sign up×
Community /Pin to ProfileBookmark

Problem calling ActiveX method from JavaScript

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>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallSep 05.2007 — You can't call ActiveX from JavaScript brecause Internet Explorer is the only browser to understand ActiveX and it doesan't understand JavaScript - it has its own similar language called JScript.

As more people are switching from IE to more modern browsers or turning off ActiveX (the major cause of security holes in IE) any such code will work for fewer and fewer people if at all.

Or is this for an intranet where you can force everyone to have an appropriate configuration. You may need to change the system configuration on the individual computers on the intranet to get it to work.
Copy linkTweet thisAlerts:
@Pera_PisarauthorSep 05.2007 — Felgall, thanks for your reply.

This should work in strictly controlled environment which means local intranet and I can access to all client machines to configure them.
Copy linkTweet thisAlerts:
@Pera_PisarauthorSep 07.2007 — 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.
×

Success!

Help @Pera_Pisar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...