Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 24th, 2004, 03:57 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old August 24th, 2004, 09:40 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 0 Times in 0 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

<><
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old August 25th, 2004, 12:09 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old August 25th, 2004, 02:52 AM
joefawcett's Avatar
Wrox Author
Points: 9,600, Level: 42
Points: 9,600, Level: 42 Points: 9,600, Level: 42 Points: 9,600, Level: 42
Activity: 4%
Activity: 4% Activity: 4% Activity: 4%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,045
Thanks: 1
Thanked 32 Times in 31 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old August 25th, 2004, 03:36 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old August 25th, 2004, 09:15 AM
joefawcett's Avatar
Wrox Author
Points: 9,600, Level: 42
Points: 9,600, Level: 42 Points: 9,600, Level: 42 Points: 9,600, Level: 42
Activity: 4%
Activity: 4% Activity: 4% Activity: 4%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,045
Thanks: 1
Thanked 32 Times in 31 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old August 26th, 2004, 01:56 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old August 26th, 2004, 02:45 AM
joefawcett's Avatar
Wrox Author
Points: 9,600, Level: 42
Points: 9,600, Level: 42 Points: 9,600, Level: 42 Points: 9,600, Level: 42
Activity: 4%
Activity: 4% Activity: 4% Activity: 4%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,045
Thanks: 1
Thanked 32 Times in 31 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old August 26th, 2004, 04:24 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old August 26th, 2004, 05:01 AM
joefawcett's Avatar
Wrox Author
Points: 9,600, Level: 42
Points: 9,600, Level: 42 Points: 9,600, Level: 42 Points: 9,600, Level: 42
Activity: 4%
Activity: 4% Activity: 4% Activity: 4%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,045
Thanks: 1
Thanked 32 Times in 31 Posts
Default

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



--

Joe (Co-author Beginning XML, 3rd edition)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
program that call its method automatically mfahadwallam BOOK: Beginning Java 2 0 January 28th, 2008 08: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 04: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 03:11 AM



All times are GMT -4. The time now is 08:05 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
© 2011 John Wiley & Sons, Inc.