Click here to Skip to main content
12,830,941 members (41,497 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 26 Oct 2006


, 26 Oct 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A small COM component (DLL) enabling scrips to provide Runtime Licence text for ActiveX controls.


If you try to embed a Microsoft ActiveX control, such as MSComm (for serial communications) inside your script (JScript, VBScript, script component), then you have to provide its Runtime License text (or key) in order to make it work on an end-user unlicensed machine (yes, you have this kind of problem only if you plan to deploy your script). I made a very small COM component (hosted by a DLL) able to provide such a license. Of course, you need to know the Runtime License text of the intended ActiveX (I have also developed an application to discover such texts on a licensed machine, i.e., a PC having Visual Studio installed on, see my article about COMLicenceFinder).


You should know how to use ActiveX controls in a script (see MSDN). A general knowledge of COM is also desirable (there are a lot of books about COM: Inside COM, Essential COM, etc...).

Using the LicenceProvider COM component

First of all, you have to register on the target machine both the LicenceProvider component and the MS ActiveX control your script uses. Then you can obtain an instance of the control by calling the Provide method of the LicenceProvider object:

var objSerial;
// Create the LicenceProvider object
var lp = new ActiveXObject("LicenceProvider.LicProvider");
// Use the LicenceProvider object to obtain an instance
// of the MsComm ActiveX, by providing a Runtime Licence text.
// Passing MsComm CLSID & Runtime
// Licence Text as argumens. 
objSerial = lp.Provide("{648A5600-2C6E-101B-82B6-000000000014}", 
                       "Copyright (c) 1994 ");

The above sample code (JScript) just shows how to obtain an instance of the MSComm, providing the Runtime License via the Provide method of the LicenceProvider object.

Points of Interest

You need to use a COM component as LicenceProvider because the only way (I know) to obtain a runtime licensed instance of any of such ActiveX controls is requesting it by the CreateInstanceLic member of the control's IClassFactory2 interface, and the latter is not directly accessible by the script. Hence the LicenceProvider is finally an adapter of the VTABLE binding to the DISPATCH one used by the automation clients (like the scripts). The steps performed are the following:
  1. Obtain a pointer to the ActiveX control Class Object IClassFactory interface.
  2. Using the obtained pointer, request another pointer, this time to the IClassFactory2 interface.
  3. Call the IClassFactory2::CreateInstanceLic to obtain an instance of the ActiveX control (in fact, a pointer to its IUnknown interface).
  4. Request the IDispatch interface pointer via the QueryInterface method of IUnknown.

The steps are shown by the sample code below:

if ( UuidFromString((unsigned char *)
       (pCLSIDBegin+1), &uuid) != RPC_S_OK )
    return E_FAIL;
HRESULT hr = CoGetClassObject(uuid, CLSCTX_ALL, 
             NULL, IID_IClassFactory, (void**)&pCF);
if ( FAILED(hr) ) return E_FAIL;
hr = pCF->QueryInterface(IID_IClassFactory2, (void **)&pCF2);
if ( FAILED(hr)) return E_FAIL;
IUnknown * pObj;
hr = pCF2->CreateInstanceLic(NULL,NULL, IID_IUnknown , 
                             lictext, (void **)&pObj); 
if ( FAILED(hr)) return E_FAIL;
pObj->QueryInterface(IID_IDispatch, (void **) pObject);

The magic of the DISPATCH to VTABLE mapping is done by the dual interface of the component (thanks to ATL).


  • 26 Oct 2006 - First release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) AEM S.p.A.
Italy Italy

Debugging? Klingons do not debug. Our software does not coddle the weak. Bugs are good for building character in the user.
-- The Klingon programmer

Beelzebub for his friends [^].

You may also be interested in...

Comments and Discussions

Questionplease help me soon Pin
kian_beh13-Jun-07 2:31
memberkian_beh13-Jun-07 2:31 
AnswerRe: please help me soon Pin
CPallini13-Jun-07 2:39
memberCPallini13-Jun-07 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 26 Oct 2006
Article Copyright 2006 by CPallini
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid