Invoke COM objects from a javascript?

Invoke COM objects from a javascript?

2
NewbieNewbie
2

    Jun 13, 2007#1

    Is it not possible to create COM objects with the java script engine that comes with UltraEdit?

    Why does not the lines below work?

    var obj = WScript.CreateObject("MyComServer.MyObject");
    var res = obj.MyMethod("test");

    I get this error message:

    An error occurred on line 7:
    obj = WScript.CreateObject("MyComServer.MyObject");
    Script failed.

    These lines of code executes just fine when I run the script outside UltraEdit (e.g. with the WScript.exe engine).

    Regards
    /Thomas

    6,677581
    Grand MasterGrand Master
    6,677581

      Jun 13, 2007#2

      Wscript.exe is the Windows Script interpreter and not a JavaScript interpreter. To be more precise, it contains (or runs) a VBScript and a JScript interpreter. JScript is not JavaScript, although similar. You should know that when you are writing Windows scripts. Have you not read the documentation. Well, I have never written a Windows script and so I have also not read the documentation about Windows scripts.

      And in help of UltraEdit you can read at top of the page titled Scripting Demo and Tutorial:

      Scripting in UltraEdit/UEStudio is enabled through embedding of the JavaScript engine. The scripting engine supports the core functionality of JavaScript 1.7. Further information on JavaScript may be found on the associated Mozilla site (http://developer.mozilla.org/en/docs/JavaScript).
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jun 13, 2007#3

        Mofi, I'm aware of that the scripting engine embedded in UltraEdit supports the core functionality of JavaScript 1.7.

        But my question remains: Is is not possible to create COM objects in a script file that is executed from UltraEdit?

        Regards
        /Thomas

        6,677581
        Grand MasterGrand Master
        6,677581

          Jun 13, 2007#4

          The UltraEdit JavaScript engine knows 3 objects: the UltraEdit application object, the UltraEdit document object and since v13.10 the UltraEdit outputWindow object. I'm not a JavaScript expert and I also have never tried to create a new object. I think, it is not possible, but maybe an expert can disprove my statement here.
          Best regards from an UC/UE/UES for Windows user from Austria

          29
          Basic UserBasic User
          29

            Jun 20, 2007#5

            I get this error message:

            An error occurred on line 7:
            obj = WScript.CreateObject("MyComServer.MyObject");
            Script failed.
            Technically the following is correct in any JavaScript environment:
            var dict = new ActiveXObject("Scripting.Dictionary");

            However it seems UltraEdit does not support it as I get the same error message you!

            16
            Basic UserBasic User
            16

              Jun 21, 2007#6

              According to the mozilla foundation, core javascript consist of the following objects:

              Array
              Boolean
              Date
              Error
              Function
              java
              JavaArray
              JavaClass
              JavaObject
              JavaPackage
              Math
              netscape
              Number
              Object
              Packages
              RegExp
              String
              sun

              But that is their core. The real core consists of:

              Array
              Boolean
              Date
              Error
              Function
              Math
              Number
              Object
              RegExp
              String

              Those are the only objects you can trust to be in any javascript enabled program. And UltraEdit added the 3 objects mofi mentioned earlier. ActiveXObject has never and will never be a part of core javascript nor will WScript. They are very platform specific objects, and ActiveXObject will only work in an ActiveX supporting browser (=Internet Explorer).

              This is also by design. Javascript does not have the capabilities to access the file system. That you are able to create a new file with javascript in UE is because the developers extended the core javascript with it's own object, which hooks javascript to the file system. As such it would be possible for the developers to create such a hook to COM objects. But it is very unlikely that this will happen any time soon. I think javascript is introduced step by step in UltraEdit.

              so yes mofi, it is possbile to create new objects

              Code: Select all

              var o = new Object();
              o.foo = 'hello';
              UltraEdit.outputWindow.write(o.foo);
              
              or even complete prototyped classes if you wish to do so.

              Code: Select all

              function Foo(nr1, nr2)
              {
              	this.nr1 = parseInt(nr1);
              	this.nr2 = parseInt(nr2);
              }
              
              Foo.prototype.nr1 = ''; // instance var
              Foo.prototype.nr2 = ''; // instance var
              Foo.version = '1'; // static var
              Foo.prototype.add = function()
              {
              	return String(this.nr1 + this.nr2)
              }
              
              var bar1 = new Foo(10, 10);
              var bar2 = new Foo(3, 3);
              
              UltraEdit.outputWindow.write(Foo.version);
              UltraEdit.outputWindow.write(bar1.add());
              UltraEdit.outputWindow.write(bar2.add());
              

              5
              NewbieNewbie
              5

                Aug 27, 2007#7

                Windows has included Windows Scripting Host for scripting applications, the operating system, etc. JScript is among the languages it supports. JScript's syntax is nearly identical to JavaScript. Hence dealing with COM with the JavaScript language syntax is not an issue.

                The problem is that UltraEdit doesn't support COM at all. Rather than processing everything internally, it should use the COM system and the WSH script runtime engine. But for some reason it does not. And without a way to exchange data with other processes and such, scripting is severely limited. Honestly I find it to be useless at present. UltraEdit still hasn't caught up w/ Windows 98!