Home > Web Front-end > JS Tutorial > body text

How to create .exe or .dll files using JScript_javascript tips

WBOY
Release: 2016-05-16 18:04:56
Original
2082 people have browsed it

What is JScript?
JScript is an active scripting language developed by Microsoft and implemented based on the ECMAScript specification. JavaScript in Internet Explorer actually refers to JScript. JScript is supported by Windows Script Host (WSH) (JavaScript shell scripting in WSH: C:> cscript jslint.js). The latest version of JScript (JScript.NET) is based on ECMAScript 4.0 and can be compiled in the .Net environment.
.NET Framwork includes a JScript compiler: JScriptCompiler (C:WINDOWSMicrosoft.NETFrameworkv2.0.50727jsc.exe), which can compile JScript files into an .exe or .dll file.
For ease of use, we can add the path of JScriptCompiler to the environment variable (environment variable –> system variable –> Path). Directly call the command "jsc" in the CMD program running window to see the compiler-related help options.

Copy code The code is as follows:

jsc [Option] [[ Options] …]

JScript Compiler Options

– Output File -
/out: Specifies the name of the binary output file
/ t[arget]:exe Create a console application (default)
/t[arget]:winexe Create a Windows application
/t[arget]:library Create a library assembly
/platform:< platform> Restricts the platforms this code can run on; must be x86, Itanium, x64, or anycpu. Defaults to anycpu

– Input files -
/autoref[ |-] Automatically reference assemblies based on imported namespaces and fully qualified names (on by default
)
/ lib: Specifies additional directories to search for references in
/r[eference]: References metadata from the specified assembly file: [ ;...]

– Resources -
/win32res: Specify Win32 resource file (.res)
/res[ource]: Embed the specified resource: [,[,public|private]]
/linkres[ource]: Link the specified resource to this assembly< info>: [,[,public|private]]

– Code generation -
/debug[ |-] Emit debugging information
/fast[ |- ] Disable language features to make code better generated
/warnaserror[ |-] Treat warnings as errors
/w[arn]: Set warning level (0-4)

– Miscellaneous -
@ For more options, read the response file
/? Show help
/help Show help
/d[efine]: Definition Conditional compilation symbols
/nologo Do not display the compiler copyright logo
/print[ |-] Provide print() function

– Advanced -
/codepage: Use the specified Codepage ID Open source file
/lcid: Use specified LCID for messages and default codepage
/nostdlib[ |-] Do not import the standard library (mscorlib.dll) and set autoref to the default value Change to off
/utf8output[ |-] Emit compiler output in UTF-8 character encoding
/versionsafe[ |-] Specify default values ​​for members not marked "override" or "hide"

Create .exe file

First create a JS file (C:testhelloWorld.js) with the following content:

var date = new Date(); print('Hello World! nToday is ' date );

Then we compile:

C:test>jsc helloWorld.jsMicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (R) .NET Framework version 2.0.50727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.
You will be surprised to find that there is an extra helloWorld.exe file in the C:test directory. It is very simple, haha

Finally we can directly execute the helloWorld.exe file:

C :test>helloWorldHello World! Today is Fri Jun 3 23:13:20 UTC 8 2011
Done! !

Create .dll file

Creating .dll file is also very simple:
Copy code The code is as follows:

package LibHW {
class HelloWorld {
function run() {
var date = new Date();
return 'Hello World! nToday is ' date;
}
}
}

Compilation statement:

C:test>jsc /t:library LibHW.js
For the generated LibHW.dll file, we can create a new .exe file (consumer.js –> ; consumer.exe) is called by importing a module (similar to Python).

First create the consumer.js file:

import LibHW;var hw = new LibHW.HelloWorld();print(hw.run());
Then compile the consumer.js file , execute consumer.exe:

C:test>jsc consumer.jsMicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (R) .NET Framework version 2.0.50727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved. C:test>consumerHello World! Today is Sat Jun 4 00:42:35 UTC 8 2011
Of course you can also create a windows application. The consumer.js file in the above example is modified as follows:
Copy code The code is as follows:

import System.Windows.Forms; // this has a MessageBox class
import LibHW ;

var hw = new LibHW.HelloWorld();
MessageBox.Show(
hw.run(),
"Dude!",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation
);

Compile statement:

C:test>jsc /t:winexe consumer.js
Double-click the newly generated consumer.exe file , Haha, isn’t it a great sense of accomplishment!

From the above example, we can see that JScript has unlimited potential.

Extended reading:
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template