I'm currently working to replace my ActiveX-Implementation in IE through a REST-API based on node.js with running edge.js
So far the basic examples from the page implementing worked pretty well. I have my index.js set up to
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);
});
And the simpleVbFunction.vb as
Async Function(Input As Object) As Task(Of Object)
Return Await Task.Run(Function()
Return "NodeJS Welcomes: " & Input.ToString()
End Function)
End Function
So far so good. Now i want to be able to access an application running on the machine running node.js. In this case Catia (could as well be Excel though)
Usually for this I'd use a simpleVbFunction.vb like this
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
However this does not work. I'm getting the following error.
Error: Unable to compile VB code. ----> Errors when compiling as a CLR library: C:\Users\xxxxxx\AppData\Local\Temp\4hf2uw3z.0.vb(1,0) : error BC30203: Bezeichner erwartet. ----> Errors when compiling as a CLR async lambda expression: C:\Users\xxxxxx\AppData\Local\Temp\cypj4ltp.0.vb(7,0) : error BC30451: "GetObject" ist nicht deklariert. Auf das Objekt kann aufgrund der Schutzstufe möglicherweise nicht zugegriffen werden. at Error (native) at Object.exports.func (C:\Users\xxxxxx\coding\node\tst_win32ole\node_modules\edge\lib\edge.js:169:17) 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 [as _onTimeout] (module.js:604:10) at ontimeout (timers.js:386:14)
Now I have to admin my VB.NET skills are a little bit rusty and this might just be an error in my VB-Code but I think it's something else. Has anyone of you been able to access a COM-Object via edge.js and if yes how was this possible?
[edit] OK. I came a little further by switching to C# from VB (At least the code commented out to access the name of the Excel Application works). But this opened another problem. My code here looks like this
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;
}
}
Now the problem is, that when working with Visual Studio and compiling the dlls get included automatically (when setting CATIA as INFITF.Application). But with edge.js I'd get the error that the namespace INFITF could not be found. Any ideas how to get that working?
Sorry for the long question. I'll tidy this up after this is solved.
[/edit]