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 August 24th, 2004, 03:57 AM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call DLL Method in Javascritp? URGENT!!!!!!

Hi,

i want to call DLL Method in Javascript .
dll name is JSDll.dll having method TestMethod().
i want to call TestMethod () from Javascript ?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type='text/javascript' language='javascript'>
function comEventOccured()
{

try{
var myobject;
myobject = new ActiveXObject("JSDll.CoTest");

alert("Test1");
alert(myobject.TestMethod()); // HERE i want to call DLL Function .
}
catch(e)
{
//if(e.message == "Automation server can't create object")
//myobject = new ActiveXObject("JCJInterface.dll");
////alert("myproject value in javascript "+myobject);
}
//action="/exchweb/bin/auth/owaauth.dll"
}
</SCRIPT></HEAD>
<BODY>
<INPUT TYPE=button value=DLL onClick="comEventOccured()">
<br>
<input type=submit value=submit >
</BODY>
</HTML>


if any answer , it should be appecripted.
regards,
prabhakar G


 
Old August 24th, 2004, 09:40 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

So, you want to call an application from a webpage to run on the client's machine. That's the most insecure operation I've ever heard of. What if your DLL is a virus? This would be a huge security hole, but it isn't, and it won't work no matter how hard you try, if I understand your desires correctly.

Snib

<><
 
Old August 25th, 2004, 12:09 AM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The DLL appication is already in use.i want to call DLL Method from javascript.

please guide to me.

regards,
prabhakar

 
Old August 25th, 2004, 02:52 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If your dll is a COM style one then you can call methods from it but only if the security settings for the zone the web page is in allow unsafe ActiveX, this would only normally be in Trusted Zone and Local Intranet. The code would be as you have already:
Code:
var obj = new ActiveXObject("JSDll.CoTest");
var vResult = obj.TestMethod();
alert(vResult);
JavaScript is case sensitive for most classes.

You could also make sure that the dll is registered, can you go into the VBA editor in Excel or Word and see it in Tools | References? If not it is not a registered COM library.

--

Joe
 
Old August 25th, 2004, 03:36 AM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai joe,

thanks for ur reply. still i 'm facing the problem calling DLL method from javascript.
i Registered COM DLL & saw the registered DLL VBA Editor tool|References also it's there(like JSDll 1.0 library).
how to make ActiveXObject unsafe in local intranet | Trusted Zone.

i 'm using WINDOWS XP .

i 'm awaiting for ur reply , thanks


regards,
prabhakar G




 
Old August 25th, 2004, 09:15 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Click on the status bar, far right, where the zone is listed. Click "Custom Level" and change settings regarding ActiveX to prompt or enable. A bit of trial and error maybe needed as to which one but my guesss would be "Initialize and script ActiveX controls not marked as safe".

--

Joe
 
Old August 26th, 2004, 01:56 AM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai Joe,

Again Thanks for reply.Still i 'm facing problem calling VC++ COM DLL Method from javascript.here i given html file also . and VC++ Method SampleMethod also .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE> Com </TITLE>
</HEAD>
<BODY >
<form action="" method="post">
<SCRIPT language="javascript">
function comEventOccured(){
try{
    alert("Before ActiveX");
    var obj =new ActiveXObject("JSDll.CoTest.1");// dll name is JSDll, class: CoTest,it'll got from //regedit repositry
    alert("After ActiveX");
    alert(obj.SampleMethod());// This is VC++ COM DLL Method
    alert("After Method");// This Alert box Not Exceuting
    //alert(vResult);
    }catch(e) {
    if(e.message == "Automation server can't create object")
        alert("myproject value in javascript "+vResult);
    }
    }
</SCRIPT>
</form>
<INPUT TYPE=button value=MethodCall onClick="comEventOccured()">
</BODY>
</HTML>

VC ++ 6 , i selected ATL COM APPWIZARD project.

i added one NEW class like CoTest, add New Member Function like SampleMethod() it's retuing int . i want any one of the method from javascript?

STDMETHODIMP CCoTest::TestMethod()
{

    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    AfxMessageBox("Inside TestMethod()");
    return S_OK;

}

int SampleMethod()
{
    AfxMessageBox("This is from Sample Method");
    return 5;

}

int CCoTest::callMethodFromJS()
{
    AfxMessageBox("This is from callMethodFromJS Method");
    return 5;
}
and This DLL Registered also through regesvr32.
after that i checkd COM Library also , this DLL Name is there (VBA Editor).And (security)Custom Level ActiveX oriented everthing i made Enable option.

still i facing same problem.

plz guide to me.

i 'm awating ur reponse.


regards,
prabhakar G


 
Old August 26th, 2004, 02:45 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you email me the dll, zipped up, to my profile address then I'll test it. Your code is hiding the error message though, just alert e.message in the catch block.

--

Joe
 
Old August 26th, 2004, 04:24 AM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai Joe ,

i 'm unable to see ur profile E-mail address.
plz send to me ur e-mail address. i 'll send to u code .

regards,
Prabhakar

 
Old August 26th, 2004, 05:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It's a hotmail.com address, my user name is joefawcett.



--

Joe (Co-author Beginning XML, 3rd edition)





Similar Threads
Thread Thread Starter Forum Replies Last Post
program that call its method automatically mfahadwallam BOOK: Beginning Java 2 0 January 28th, 2008 09:26 AM
Calling a function on every method call Takashi321 General .NET 1 September 21st, 2007 09:33 AM
Can I call a method that populate a Label??? cp75 ASP.NET 1.0 and 1.1 Basics 2 January 12th, 2007 05:39 AM
how to call a method from childMDI1 into childMDI2 raj_k C# 0 June 26th, 2005 04:54 PM
How to call a C# method from VB.Net? aliarifpk General .NET 1 February 26th, 2004 04:11 AM





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