I drive into this issue:
I create COM object using C#, register it and managed to work with it using powershell.
when i trying to do the same with JavaScript it fails, but javascript keeps throwing object null errors.
Do you have any advice on how to fix this problem? or maybe you JavaScript doesn't support COM (if so, where can i read more about it)???
Thanks a lot!
Use Shanti Rao's JSDB shell. It's based on the core Spidermonkey engine (Mozilla's Javascript implementation) used in Firefox, but has a bunch of bindings for databases & ActiveX objects and such. It has a few limitations but unless you're using something complicated you should be able to make use of it.
Example:
x=new ActiveX('MSXML2.DOMDocument.6.0');
x.async = false;
// I forget how to use IXMLDOMDocument but other calls go here
Javascript indeed does not support COM. An option is to use JScript and an ActiveX wrapper to a COM object. Also, it will only work in Internet Explorer.
Instantiating a COM class
Calling functions of a COM object in JScript
Other JScript/COM tutorials, including script callbacks
I know this is a bit late, but for others who find this, yes this can be done easily. This assumes you're running on Windows since you're looking for Windows/JavaScript interoperability.
The most important question is "what JavaScript engine are you using?" as this functionality is determined by that engine. Since 1995, Windows has supported a system standard scripting model originally called OLE Automation or sometimes just COM. Windows-based scripting engines like the JavaScript and VBScript engines built into the Windows Scripting Host use this engine, in addition to IE through version 8 and I think up to 11. However, the IE container implements security restrictions that prevent some of what I'm describing from working. Open-source JavaScript engines like node.js typically do not use COM as this is Windows specific functionality and so cannot do what I am describing.
Given that, to accomplish what you want, you must:
1. Implement a scriptable COM object.
2. Register that object (typically automatic during your build process).
3. In JavaScript, create an instance of that object using new ActiveX object, as mentioned above.
You can write your object in both C# and C++. In both cases, you need to base your object on IDispatch. C# will make the whole process considerably easier. Essentially, you generate a few unique GUIDs for your interface and component using guidgen, then using a few COM-specific attributes in C# to provide these. Here's a link to a great simple example (ignore the Events stuff):
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/example-com-class
The most important thing to know is that you will be limited on what data types you can take as parameters or return to the caller. Things like strings and ints are no problem. For others, you can describe them in C# and send them from C# to JavaScript, but the other way around is not going to work.