c调用javascript
来源:互联网 发布:polyfit函数的算法 编辑:程序博客网 时间:2024/05/17 07:54
操作步骤:
1、下载获得js-1.60.tar.gz的tarball并解压,下载地址:http://ftp.mozilla.org/pub/mozilla.org/js/
2、 用vc6打开src目录下的js.mdp,vc6会提示你转换到新版的dsp,确定会得到3个dsp工程文件;
3、 分别设定这三个文件为Active Project同时分别编译得到js32.dll和js32.lib
4、 把上述2个文件以及src下的*.h复制到你的应用程序目录下(或者通过选项卡设定Project的头文件包含路径)
5 新建"Win32 console applation"型的工程,编写C代码进行测试,如下:
#include <string.h> //for strlen
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#define XP_WIN
#include "jsapi.h"
#pragma comment(lib, "js32.lib")
int main(int argc,const char* argv[])
{
JSRuntime *runtime = NULL;
/* pointer to our context */
JSContext *context = NULL;
/* pointer to our global JavaScript object */
JSObject *global = NULL;
/* script to run (should return 100) */
const char *script = "var a=5;b=6;a+b;";
/* JavaScript value to store the result of the script */
jsval rval;
/* create new runtime, new context, global object */
if ((!(runtime = JS_NewRuntime(1024L * 1024L)))
|| (!(context = JS_NewContext(runtime, 8192)))
|| (!(global = JS_NewObject(context, NULL, NULL, NULL)))
)
return EXIT_FAILURE;
/* set global object of context and initialize standard ECMAScript
* objects (Math, Date, ...) within this global object scope */
if (!JS_InitStandardClasses(context, global))
return EXIT_FAILURE;
/* now we are ready to run our script */
if (!JS_EvaluateScript(context, global, script, strlen(script), "script", 1, &rval))
return EXIT_FAILURE;
printf("the script's result is \n%d\n",JSVAL_TO_INT(rval));
/* clean up */
JS_DestroyContext(context);
JS_DestroyRuntime(runtime);
JS_ShutDown();
return EXIT_SUCCESS;
}
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#define XP_WIN
#include "jsapi.h"
#pragma comment(lib, "js32.lib")
int main(int argc,const char* argv[])
{
JSRuntime *runtime = NULL;
/* pointer to our context */
JSContext *context = NULL;
/* pointer to our global JavaScript object */
JSObject *global = NULL;
/* script to run (should return 100) */
const char *script = "var a=5;b=6;a+b;";
/* JavaScript value to store the result of the script */
jsval rval;
/* create new runtime, new context, global object */
if ((!(runtime = JS_NewRuntime(1024L * 1024L)))
|| (!(context = JS_NewContext(runtime, 8192)))
|| (!(global = JS_NewObject(context, NULL, NULL, NULL)))
)
return EXIT_FAILURE;
/* set global object of context and initialize standard ECMAScript
* objects (Math, Date, ...) within this global object scope */
if (!JS_InitStandardClasses(context, global))
return EXIT_FAILURE;
/* now we are ready to run our script */
if (!JS_EvaluateScript(context, global, script, strlen(script), "script", 1, &rval))
return EXIT_FAILURE;
printf("the script's result is \n%d\n",JSVAL_TO_INT(rval));
/* clean up */
JS_DestroyContext(context);
JS_DestroyRuntime(runtime);
JS_ShutDown();
return EXIT_SUCCESS;
}
- c调用javascript
- javascript调用C#BHO
- 从C调用JavaScript函数代码。
- javascript如何调用objective-c的方法
- 从C调用JavaScript函数代码。
- c#Activex控件中调用JavaScript
- JavaScript与Objective-C的互相调用
- Unity3D: JavaScript->C# 或 C#->JavaScript的调用
- C#.net 后台cs 调用前台javascript 的方法
- javascript与asp.net(c#)互相调用方法
- JavaScript引擎研究与C、C++与互调用
- c#、javascript AJAX、和jquery调用webservice的方法
- 使用UIWebView时objective-c与javascript互相调用 1
- 使用UIWebView时objective-c与javascript互相调用 1
- [C#]ActiveX控件调用页面上的JavaScript
- JavaScript引擎研究与C、C++与互调用
- JavaScript引擎研究与C、C++与互调用
- [iOS] 使用UIWebView时objective-c与javascript互相调用
- 在线客服 浮动窗口
- 鬼哥Csdn免积分在线下载器v10.0-网页版
- CentOS后台任务执行相关命令
- 不使用官方SDK,实现微信分享(发送到朋友,发送到朋友圈)
- IOS 应用程序间跳转
- c调用javascript
- 每日一算法:全排列的递归算法与非递归算法
- 技术不牛如何才拿到国内IT巨头的Offer
- Metronic V1.5.2 Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0
- Oracle API笔记
- 基于石墨烯的微波毫米波器件在国防航空领域的应用
- php smarty
- sql 行转列 PIVOT 列转行 UNPIVOT
- Spring中的FactoryBean