 |
| 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
|
|
|
|

August 24th, 2004, 03:57 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 24th, 2004, 09:40 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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
<><
|
|

August 25th, 2004, 12:09 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The DLL appication is already in use.i want to call DLL Method from javascript.
please guide to me.
regards,
prabhakar
|
|

August 25th, 2004, 02:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

August 25th, 2004, 03:36 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 25th, 2004, 09:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

August 26th, 2004, 01:56 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 26th, 2004, 02:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

August 26th, 2004, 04:24 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 26th, 2004, 05:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
It's a hotmail.com address, my user name is joefawcett.
--
Joe (Co-author Beginning XML, 3rd edition)
|
|
 |