目前,我正在通过基于node.js的REST-API,用运行edge.js替换我在IE中的ActiveX实现。
到目前为止,页面实现中的基本示例工作得很好。我的index.js设置为
var edge = require('edge');
var edgeVb = require('edge-vb');
var path = require('path');
var helloVb = edge.func('vb', path.join(__dirname, 'simpleVbFunction.vb'));
helloVb('Testing with String', (err, res) => {
if(err) throw err;
console.log(res);
});而simpleVbFunction.vb作为
Async Function(Input As Object) As Task(Of Object)
Return Await Task.Run(Function()
Return "NodeJS Welcomes: " & Input.ToString()
End Function)
End Function到目前一切尚好。现在,我希望能够访问运行node.js的机器上运行的应用程序。在这种情况下,Catia (也可以是Excel )
通常情况下,我会使用这样的simpleVbFunction.vb
Async Function(Input As Object) As Task(Of Object)
Return Await Task.Run(Function()
Dim CATIA as Object
set CATIA = GetObject(, "CATIA.Application")
Return CATIA.ActiveDocument.Application.FullName
End Function)
End Function然而,这是行不通的。我得到了以下错误。
错误:无法编译VB代码。->编译为CLR库时的错误: C:\Users\xxxxxx\AppData\Local\Temp\4hf2uw3z.0.vb(1,0):error BC30203: Bezeichner .奥弗德奥巴杰克恩aufgrund der Schutzstufe m glicherweise nicht zugegriffen .(C:\Users\xxxxxx\coding\node\tst_win32ole\node_modules\edge\lib\edge.js:169:17) at Object.exports.func at Object时出现错误(本机)。(C:\Users\xxxxxx\coding\node\tst_win32ole\index.js:6:20) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Timeout.Module。runMain onTimeout at ontimeout (timers.js:386:14)
现在我不得不管理我的VB.NET技能有点生疏,这可能只是我的VB代码中的一个错误,但我认为这是另一回事。你们中有人能够通过edge.js访问COM对象吗?如果是的话,这怎么可能?
编辑好了。通过从VB切换到C# (至少注释掉了访问名称的代码),我走得更远了。但这又带来了另一个问题。我的代码如下所示
using System.Threading.Tasks;
using System;
using System.Runtime.InteropServices;
// using INFITF;
public class Startup
{
public async Task<object> Invoke(object input)
{
// dynamic xl = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
// return xl.Name;
object CATIA0 = Marshal.GetActiveObject("CATIA.Application");
INFITF.Application CATIA = CATIA0 as INFITF.Application;
}
} 现在的问题是,当使用Visual并编译dll时(当将CATIA设置为INFITF.Application时)会自动包含。但是使用edge.js,我会得到名称空间INFITF找不到的错误。有什么办法让它起作用吗?
很抱歉有这么长的问题。这件事解决后我会收拾一下的。
/edit
发布于 2017-11-13 13:29:56
好的。大部分都算出来了。首先,由于您没有使用IDE,也不会像以前那样添加重新源,这将与edge.js不同。您必须找到您的dll并实现它。在我的情况下,我必须找到
Interop.INFITF.dll
从Catia目录。
在此之后,您的node.js代码将如下所示。(我现在用于测试的功能仅仅是,每秒钟我将在Catia中记录当前打开的部分的名称)
var edge = require('edge');
var path = require('path');
var getCat = edge.func({
source: path.join(__dirname, 'accessCatia.cs')
, references :[
'./Resources/Interop.INFITF.dll'
]});
setInterval(function(){
getCat('someInputString', (err, res)=>{
if(err){
console.log('ERROR FOUND: ');
console.log(err);
return;
}
console.log(res);
});
},1000);我的accessCatia.cs会像这样。
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System;
public class Startup
{
public async Task<object> Invoke(object input)
{
object cat0 = Marshal.GetActiveObject("Catia.Application");
INFITF.Application cat = cat0 as INFITF.Application;
INFITF.Document doc = cat.ActiveDocument as INFITF.Document;
return doc.FullName;
}
}现在仍然开放的是,对象接收的结构似乎与您在Internet中使用VB.net或通过ActiveX获得的结构不同。例如
doc.FullName作为常规存在,但是在使用C#时将找不到doc.Name,而是必须使用doc.get_Name()。
不幸的是,DassaultSystems在文档方面非常糟糕,但这可能是另一个主题的内容。
https://stackoverflow.com/questions/47222386
复制相似问题