Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Using .NET objects from good-ol JScript

Using .NET objects from good-ol JScript

Scheduled Pinned Locked Moved .NET (Core and Framework)
comcsharptoolsquestionworkspace
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nick Blumhardt
    wrote on last edited by
    #1

    Hi all, I was wondering if anyone out there had tried using .NET objects from a pre-.NET scripting environment (I want to use Windows Script hosted JScript). I'm sure it is possible through COM interop, but can anyone tell me of an article or web page to get this running quickly and easily? Thanks for any suggestions, Nick

    S 1 Reply Last reply
    0
    • N Nick Blumhardt

      Hi all, I was wondering if anyone out there had tried using .NET objects from a pre-.NET scripting environment (I want to use Windows Script hosted JScript). I'm sure it is possible through COM interop, but can anyone tell me of an article or web page to get this running quickly and easily? Thanks for any suggestions, Nick

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      You can call a .NET component from the outside world. That's done through CCW, COM Callable wrapper, which is by the way the keyword to use to find articles on Cp, MSDN, ... The procedure is as follows : - write a component using C#, or whatever .NET language you can think of - register the component to the unmanaged world using the regasm.exe cmdline. Doing so, this component looks like a standard COM component, except the fact that the InProcServer32/LocalServer32 registry key points to mscoree.dll instead (that's the CLR entry point). - use JScript to create an instance of this object. Here is how you create COM instances :

      var ExcelSheet;
      ExcelApp = new ActiveXObject("Excel.Application");
      ExcelSheet = new ActiveXObject("Excel.Sheet");

      // Make Excel visible through the Application object.
      ExcelSheet.Application.Visible = true;
      // Place some text in the first cell of the sheet.
      ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
      // Save the sheet.
      ExcelSheet.SaveAs("C:\\TEST.XLS");
      // Close Excel with the Quit method on the Application object.
      ExcelSheet.Application.Quit();

      A useful link[^] on MSDN.

      N 1 Reply Last reply
      0
      • S Stephane Rodriguez

        You can call a .NET component from the outside world. That's done through CCW, COM Callable wrapper, which is by the way the keyword to use to find articles on Cp, MSDN, ... The procedure is as follows : - write a component using C#, or whatever .NET language you can think of - register the component to the unmanaged world using the regasm.exe cmdline. Doing so, this component looks like a standard COM component, except the fact that the InProcServer32/LocalServer32 registry key points to mscoree.dll instead (that's the CLR entry point). - use JScript to create an instance of this object. Here is how you create COM instances :

        var ExcelSheet;
        ExcelApp = new ActiveXObject("Excel.Application");
        ExcelSheet = new ActiveXObject("Excel.Sheet");

        // Make Excel visible through the Application object.
        ExcelSheet.Application.Visible = true;
        // Place some text in the first cell of the sheet.
        ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
        // Save the sheet.
        ExcelSheet.SaveAs("C:\\TEST.XLS");
        // Close Excel with the Quit method on the Application object.
        ExcelSheet.Application.Quit();

        A useful link[^] on MSDN.

        N Offline
        N Offline
        Nick Blumhardt
        wrote on last edited by
        #3

        Thanks, I looked around for a while but unless you know a couple of 'magic keywords' like CCW its pretty hard to search for anything containing .NET and JScript. Thanks again, there are a world of cool possibilities for this stuff :cool:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups