This project is read-only.

init ActiveX using typescript

Topics: General, Language Specification
Oct 24, 2013 at 11:17 AM
how can i create ActiveX object using TypeScript, as there is no support for CreateObject
Oct 24, 2013 at 5:22 PM
Use 'new ActiveXObject(...)'. Documented here:
Oct 24, 2013 at 5:23 PM
To call use any symbol, or call any function, that TypeScript doesn't have type information for out of the box, you need to 'declare' this symbol as being available to script. You might have seen the .d.ts files like jquery.d.ts, which do this for the jQuery library.

For CreateObject, you can do a simple trick to be able to call it:
declare var CreateObject;
var myObj = CreateObject("Excel.Application", "MyServer");
This lets you call CreateObject however you like.
Oct 24, 2013 at 7:42 PM
i have used

var helper1 = new ActiveXObject("Helper.WebHelper"); which is working but when i tried

var objElement = document.createElement('object');
        objElement.classid = 'clsid:2F3BC10B-45B6-472D-859C-200197E7D9C7'; = 'PlayerComponentX1'; = objectId; = 'data:application / x - oleobject; base64, C8E7L7ZFLUeFnCABl + fZxwAIAABqJQAAxRoAAA =='; 
var helper = document.getElementById('PlayerComponentX1');

typescript dont compile and i get exception in the web page
Oct 25, 2013 at 7:25 PM
For the TypeScript errors, I see two:
  • Could not find symbol 'objectId'
  • The property 'InitManager' does not exist on value of type 'HTMLElement'
For the first error, I assume you have objectId getted set somewhere outside of your example.

For the second error, you're dynamically getting an object from the web page called "PlayerComponentX1". You need to tell TypeScript what the type of this element is, or it will default to the simplest one called 'HTMLElement', which won't have the special methods you're invoking.

You do this by creating an interface for the type, like this:
interface PlayerComponentElement extends HTMLElement {
    InitManager(string): any;

var helper = <PlayerComponentElement>document.getElementById('PlayerComponentX1'); 
If you're having exceptions on the web page, I would simplify and write this piece in JavaScript and try to get that to work. Once the code runs without exception, you should be able to port it to TypeScript using the steps mentioned above.