Click here to Skip to main content
Licence CPOL
First Posted 26 Oct 2006
Views 23,839
Bookmarked 22 times

LicenceProvider

By | 26 Oct 2006 | Article
A small COM component (DLL) enabling scrips to provide Runtime Licence text for ActiveX controls.

Introduction

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).

Background

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);
pCF->Release();
if ( FAILED(hr)) return E_FAIL;
IUnknown * pObj;
hr = pCF2->CreateInstanceLic(NULL,NULL, IID_IUnknown , 
                             lictext, (void **)&pObj); 
pCF2->Release();
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).

History

  • 26 Oct 2006 - First release.

License

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

About the Author

CPallini

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

Member





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 [^].





Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionplease help me soon Pinmemberkian_beh1:31 13 Jun '07  
AnswerRe: please help me soon PinmemberCPallini1:39 13 Jun '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 26 Oct 2006
Article Copyright 2006 by CPallini
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid