Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows 8/.Net 4.5中嵌入Chakra Javascript引擎_Javascript_.net_Windows 8_Chakra - Fatal编程技术网

在Windows 8/.Net 4.5中嵌入Chakra Javascript引擎

在Windows 8/.Net 4.5中嵌入Chakra Javascript引擎,javascript,.net,windows-8,chakra,Javascript,.net,Windows 8,Chakra,鉴于Javascript在Windows 8中的兴起,Windows 8/.Net 4.5/VS 2012是否提供了一种机制,将Chakra Javascript引擎嵌入到应用程序中以启用脚本?如果是这样的话,在什么地方有这样的文档吗?没有发布或讨论过这样做的机制。目前,它仅在IE和Metro风格的应用程序中可用。甚至没有Windows脚本主机风格的公开 你想在脚本中使用什么样的脉轮?IE ActiveX不使用与IE standalone相同的JavaScript引擎吗 您只需嵌入Interne

鉴于Javascript在Windows 8中的兴起,Windows 8/.Net 4.5/VS 2012是否提供了一种机制,将Chakra Javascript引擎嵌入到应用程序中以启用脚本?如果是这样的话,在什么地方有这样的文档吗?

没有发布或讨论过这样做的机制。目前,它仅在IE和Metro风格的应用程序中可用。甚至没有Windows脚本主机风格的公开


你想在脚本中使用什么样的脉轮?

IE ActiveX不使用与IE standalone相同的JavaScript引擎吗

您只需嵌入Internet Explorer ActiveX框架并将其隐藏即可。

是,存在

见:


}

根据您的需要,您可能可以使用另一个JavaScript实现,如Jint或IronJS。(Jurassic可能不起作用——它P/Invoke到V8,我认为Metro应用程序中不允许P/Invoke。)另外,您好Steve,在我的情况下,我需要从Windows应用商店应用程序和WPF调用javascript。我们正在WPF中为Windows8和它的弟弟开发一个应用程序。我需要使用JavaScript作为脚本语言。一方面,我有一个字符串,表示.NET中的脚本和对象模型。我需要将该对象模型传递给脚本,以便脚本在其上运行。在Win Store应用程序和传统的.NET中,你有没有注意到这一点?它可能是两种不同的机制。请考虑在StAccExcel中添加一个代码示例,因为链接可能会被破坏,或者可能会删除回购协议。
 using System;
 using System.Runtime.InteropServices;
 using ChakraHost.Hosting;

public class HelloWorld
{
    static void Main() {
    JavaScriptRuntime runtime;
    JavaScriptContext context;
    JavaScriptSourceContext currentSourceContext = JavaScriptSourceContext.FromIntPtr(IntPtr.Zero);
    JavaScriptValue result;

    // Your script, try replace the basic hello world with something else
    string script = "(()=>{return \'Hello world!\';})()";

    // Create a runtime. 
    Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime);

    // Create an execution context. 
    Native.JsCreateContext(runtime, out context);

    // Now set the execution context as being the current one on this thread.
    Native.JsSetCurrentContext(context);

    // Run the script.
    Native.JsRunScript(script, currentSourceContext++, "", out result);

    // Convert your script result to String in JavaScript; redundant if your script returns a String
    JavaScriptValue resultJSString;
    Native.JsConvertValueToString(result, out resultJSString);

    // Project script result in JS back to C#.
    IntPtr resultPtr;
    UIntPtr stringLength;
    Native.JsStringToPointer(resultJSString, out resultPtr, out stringLength);

    string resultString = Marshal.PtrToStringUni(resultPtr);
    Console.WriteLine(resultString);
    Console.ReadLine();

    // Dispose runtime
    Native.JsSetCurrentContext(JavaScriptContext.Invalid);
    Native.JsDisposeRuntime(runtime);
}