Windows Mobile Developer Network Forum

Windows Mobile Developer Network Forum
It is currently Fri Jul 30, 2010 2:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 

Rate this article
1 0%  0%  [ 0 ]
2 0%  0%  [ 0 ]
3 0%  0%  [ 0 ]
4 0%  0%  [ 0 ]
5 100%  100%  [ 2 ]
Total votes : 2
Author Message
 Post subject: Jscript support on Windows Mobile
PostPosted: Wed Nov 01, 2006 7:37 pm 
Offline
PPCDN Team

Joined: Tue Apr 01, 2003 6:28 pm
Posts: 229
Location: Saint-Petersburg, Russia
Windows Mobile devices contain Active Scripting components responsible for parsing and running Jscript and VBScript code. So it is possible dynamically extend application functionality with some Jscript code. Defiantly there are some Jscript, JavaScript or ECMA Script implementations that could be compiled for Windows Mobile, but with Active Script Hosting the overhead in size is minimal because of most of code already on device. In this article I’ll try to show how to use Jscript in your native application.

<h2>What You Need</h2><ul><li>Microsoft Visual Studio 2005</li><li>Pocket PC 2003 SDK</li><li><a href="/articles/samples/JScriptWindowsMobile.zip">sample application</a></li></ul>

<img src="/articles/images/JScriptSupport.gif" alt="screenshot" align="right"/>Please download a sample application that could be used for running different Jscript samples. This is dialog based application that could open and run Jscript files.

Using this code you can highly extend your application with powerful dynamic language with a great features such as closures and reference counted object management.

All code connected with scripting is placed into ScriptingSupport.cpp and ScriptingSupport.h files. There are three classes in these files. CScriptingSupportHelper is a front end of this small library. Usage is quite straightforward. At first call Create with window to which Jscript application could draw. After that call RunScript with script body as a parameter. That’s all! If your script doesn’t contains any errors it is already run.

Other class is CCodeObject. It is contains dispatch methods that could be invoked from script (in my implementation these methods are Line, Ellipse and DrawText) and methods used to invoke some script code (OnPaint, OnMouseClick) . You should change these methods to methods specific for your application.
CscriptSite implements IActiveScriptSite interface and it is responsible for interaction between your application and script engine. Engine calls different methods of this class when it needs information about some object , state of script changes or error appears.

Zip file with sample program also contains small Jscript file sample.js that could be opened and executes in sample application. Screenshot on the right shows results of this file execution followed few clicks. Contents of script is
<pre>function Point(x, y)
{
this.x = x;
this.y = y;
}

Point.prototype = {
draw: function() {
Line(this.x-4, this.y, this.x+5, this.y);
Line(this.x, this.y-4, this.x, this.y+5);
DrawText("("+this.x+","+this.y+")", this.x+8, this.y-8, 60, 20);
}
}

var clicks = [];

function OnPaint()
{
for (var i = 0; i < clicks.length; i++) {
clicks[i].draw();
}
}

function OnMouseClick(x, y)
{
var p = new Point(x, y);
p.draw();
clicks.push(p);
}</pre>


If you like VBScript more then Jscript you need to make few small changes (ProgId “JScript” should be changed to “VBScript”, “js” extension should be changed something more sutable for VBScript such as “vbs”, and Jscript code should be ported to VBScript).

<h2>Related Resources</h2><ul><li><a href="http://msdn.microsoft.com/scripting/">Scripting at MSDN</li></ul>

_________________
Andrey Yatsyk


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 05, 2006 1:49 am 
Offline
Site Admin

Joined: Wed Dec 14, 2005 5:04 pm
Posts: 30
Location: Russia,St.Petersburg
Andrew, good article!

_________________
With best regards
Serg Podtynnyi
http://spbclub.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 10:29 pm 
Offline
PPCDN Team

Joined: Wed May 14, 2003 4:07 pm
Posts: 1473
Location: Lisbon, Portugal
This opens up lots of very interesting possibilities! Congrats! This totally ROCKS!

_________________
Regards,

João Paulo Figueira
Device Application Development MVP


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 09, 2006 6:21 pm 
Offline
PPCDN Team

Joined: Tue Apr 01, 2003 6:28 pm
Posts: 229
Location: Saint-Petersburg, Russia
Thank you, guys!

_________________
Andrey Yatsyk


Top
 Profile  
 
 Post subject: Windows Mobile 5.0
PostPosted: Thu Nov 23, 2006 12:21 am 
Offline

Joined: Thu Oct 26, 2006 7:23 am
Posts: 2
Location: Norway
Hi!

How difficult would it be to port this jscript engine to a Windows Mobile 5.0 device? Is it possible?

Thanks,

Espen Ekvang


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group