Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2007, 02:53 AM
Registered User
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling ActiveX component 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>
 
Old September 5th, 2007, 06:50 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Wow, that's a really good question! I hope someone has more information on it than I do. You're definitely close. If it's recognizing the object, you should be half way home, unless the error is misleading. There's probably some small element of syntax that we're both missing here. I wish I could see it.

If you haven't already, I would suggest posting this to the C++ board as well. It seems perfectly appropriate to ask there if anyone knows the Javascript to tie in your C++ code, and they may have more experience doing what you need. I do some C#, but I've never hacked C++ before which is probably why I'm not seeing it.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old September 6th, 2007, 02:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

A lot of this depends on how you wrote the C++ code and how you declared the method. Scriptable methods usually neeed variants for eaxmple. Can you show the code?

--

Joe (Microsoft MVP - XML)
 
Old September 7th, 2007, 07:58 AM
Registered User
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have solved the problem!!!

Thank you for your answers.

The problem wasn't at all in javascript, but in ocx file as I assumed later. You were right!

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Java Method via javascript basildudin J2EE 5 October 16th, 2008 12:00 AM
ActiveX Component cannot create Object Madhivanan VB How-To 5 December 23rd, 2006 02:33 AM
cannot create activex component - help please cobweb Classic ASP Components 1 September 14th, 2006 08:40 PM
Cannot create ActiveX Component Ron Howerton Pro VB.NET 2002/2003 0 July 18th, 2006 10:33 AM
activex component msrnivas Classic ASP Components 0 January 6th, 2004 11:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.