1

Do you know any tutorial for creating MFC ActiveX objects that can be used in JScript or VBScript (Windows Script Based Host)?

I mean an OCX that can be used as:

var x= new ActiveXObject("name");

and NOT this:

<object id="xxx" classid="CLSID:xxxx">

so far everything that I found just allow using an activex with html tags and they fail to initialize with script engine.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
el_shayan
  • 2,735
  • 4
  • 28
  • 42
  • Have you seen http://stackoverflow.com/questions/150814/how-to-handle-an-activex-event-in-javascript ? – MSalters Jan 04 '12 at 20:48

3 Answers3

2

Just to add some extra options: 1. Old vb6 was adept at creating ActiveX/COM components quite simply. 2. Other languages like Delphi and PowerBasic can easily create components too. 3. VBScript can be used to create com components which are packaged in a com wrapper WSC (Windows Script Component). This contains your class and code and is usable as a COM object. The WSC uses an external Script Component Runtime to execute your script when called via COM. The actual internal code can be written in other script languages, such as jscript or python or a number of others.

andora
  • 1,326
  • 1
  • 13
  • 23
1

FireBreath plugins can be used that way. It doesn't use MFC, but you haven't specified why you need to use MFC.

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • In its website, everywhere "object" tag is used. Are you sure it is possible? – el_shayan Jan 05 '12 at 12:00
  • it's just a really unusual use case, since that method only works on IE. btw, when you dropped into the IRC room I was asleep and you were gone before I got back. – taxilian Jan 05 '12 at 16:40
1

As far as getting started goes, I highly recommend you check out A Beginner Tutorial for Writing Simple COM/ATL DLL and Using it with .NET by ThatsAlok.

I've tried a number of different techniques in creating ActiveX objects, and, I found the ATL C++ to be one of my favourites. The key essentials of the tutorial are:

  • Utilizing Visual Studio ATL Simple Object wizard
  • Naming the interface in C++ (e.g. ISimpleCom)
  • Choosing a progid (e.g. SimpleATLcom.SimpleCom)
  • Letting Visual Studio generate as much code for you as possible
  • Registering your COM DLL

Some things the tutorial doesn't cover is:

  • Avoid Project Build Error PRJ0050 by registering your COM DLL using Per-user redirection which Visual Studio 2008 supports (see Microsoft MSDN article on Linker Property Pages)
  • Invoking in JScript / VBScript from Windows Script Host / HTML

The latter, you already know how to do that, but, for completeness. In JScript, it's:

var obj = new ActiveXObject("SimpleATLcom.SimpleCom");

And, in VBScript, it's:

Dim obj
Set obj = CreateObject("SimpleATLcom.SimpleCom")
Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
  • As an FYI, the ATL C++ method is the one that FireBreath plugins utilize; these are good resources. – taxilian Feb 05 '12 at 00:22