在 C# 中为 64 位项目调用 Javascript 函数 [英] Calling the Javascript functions inside C# for a 64 bit project

查看:28
本文介绍了在 C# 中为 64 位项目调用 Javascript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 C# 代码内部调用 Javascript 函数eval"(以利用字符串到运算符解析器).我使用了以下代码:https://stackoverflow.com/a/12431435/712700

I am trying to call the Javascript function "eval" from inside C# code (to utilise the string to operators parser). I used the following code: https://stackoverflow.com/a/12431435/712700

它崩溃了,并显示以下消息---:

It crashes though with the following message--- :

异常详细信息: System.Runtime.InteropServices.COMException:检索具有 CLSID 的组件的 COM 类工厂{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}由于以下原因失败错误:80040154 类未注册(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG)).

Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

我相信问题是因为项目/机器是 64 位的.我不想将项目更改为 32 位,是否可以使用另一个 CLSID 使其与 64 位一起使用?或者是否有另一种方法可以在 C# 代码中简单地利用 Javascript 中的eval"函数?

I believe the problem is because the project/machine is 64 bit. I do not want to change the project to 32 bit, is there another CLSID I can use to make it work with 64 bit? Or is there another approach to simply utilise the "eval" function from Javascript within C# code?

推荐答案

你指的是下面的代码

Type scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));

dynamic obj = Activator.CreateInstance(scriptType, false);
obj.Language = "javascript";

var res = obj.Eval("a=3; 2*a+32-Math.sin(6)");

上面的ClSID其实是给ScriptControl的

The above ClSID is actually for the ScriptControl

  • Adding a ScriptControl - Language Parameter
  • Using ScriptControl Methods - Eval Method

从上面的 2 个链接中,您将看到这是与 VB6 相关的,如果您想使用问题中提到的上述代码,您将需要 msscript.ocx.请检查您是否有此文件.您可能必须使用 regsvr32 正确注册它

From the 2 above links you will see that this is VB6 related and if you want to use the code above as mentioned in your question you will need msscript.ocx. Please check if you have this file. You may have to register it correctly using regsvr32

我使用的是 64 位机器,我在以下文件夹中看到该文件 C:WindowsSysWOW64

I am using a 64-bit machine and I see the file in the following folder C:WindowsSysWOW64

这篇关于在 C# 中为 64 位项目调用 Javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆