Home COM GDI+ WebBrowser Data Access

IClassFactory2 Interface

 

IID_IClassFactory2

{B196B28F-BAB4-101A-B69C-00AA00341D07}

 

 

The IClassFactory2 interface enables a class factory object, in any sort of object server, to control object creation through licensing. This interface is an extension to IClassFactory. This extension enables a class factory executing on a licensed machine to provide a license key that can be used later to create an object instance on an unlicensed machine. Such considerations are important for objects like controls that are used to build applications on a licensed machine. Subsequently, the application built must be able to run on an unlicensed machine. The license key gives only that one client application the right to instantiate objects through IClassFactory2 when a full machine license does not exist.

 

 

Methods in VTable order

IUnknown Methods

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

IClassFactory Methods

Description

CreateInstance

Creates an uninitialized object.

LockServer

Locks object application open in memory.

IClassFactory2 Methods

Description

GetLicInfo

Fills a LICINFO structure with information on the licensing capabilities of this class factory.

RequestLicKey

Creates and returns a license key that the caller can save and use later in calls to CreateInstanceLic.

CreateInstanceLic

Creates an instance of the licensed object given a license key from RequestLicKey.

 

LICINFO Structure

 

The LICINFO structure contains parameters that describe the licensing behavior of a class factory that supports licensing. The structure is filled during the GetLicInfo method.

 

TYPE LICINFO
   cbLicInfo AS DWORD
   fRuntimeKeyAvail AS LONG

   fLicVerified AS LONG

END TYPE

 

 

GetLicInfo

 

FUNCTION IClassFactory2_GetLicInfo ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pLicInfo AS LICINFO _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[5] USING IClassFactory2_GetLicInfo (pthis, pLicInfo) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IClassFactory2_GetLicInfo ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pLicInfo AS LICINFO _

  ) AS LONG

  ! mov  eax, pLicInfo
  ! push eax
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+20]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

RequestLicKey

 

FUNCTION IClassFactory2_RequestLicKey ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwReserved AS DWORD _

, BYREF strKey AS STRING _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[6] USING IClassFactory2_RequestLicKey (pthis, dwReserved, strKey) TO HRESULT

  strKey = ACODE$(strKey)
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IClassFactory2_RequestLicKey ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwReserved AS DWORD _

, BYREF strKey AS STRING _

  ) AS LONG
 

  LOCAL pbstrKey AS DWORD

  strKey = UCODE$(strKey)

  pbstrKey = STRPTR(strKey)


  ! lea  eax, pbstrKey
  ! push eax
  ! push dwReserved
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+24]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

CreateInstanceLic

 

FUNCTION IClassFactory2_CreateInstanceLic ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pUnkOuter AS DWORD _

, BYVAL pUnkReserved AS DWORD _

, BYREF riid AS GUID _

, BYVAL strKey AS STRING _

, BYREF ppvObj AS DWORD _

  ) AS LONG
 

  LOCAL HRESULT AS LONG

  strKey = UCODE$(strKey)
  CALL DWORD @@pthis[7] USING IClassFactory2_CreateInstanceLic (pthis, pUnkOuter, pUnkReserved, %NULL, riid, strKey, ppvObj) TO HRESULT
  FUNCTION = HRESULT
 

END FUNCTION

 

 

 

FUNCTION IClassFactory2_CreateInstanceLic ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pUnkOuter AS DWORD _

, BYVAL pUnkReserved AS DWORD _

, BYREF riid AS GUID _

, BYVAL strKey AS STRING _

, BYREF ppvObj AS DWORD _

  ) AS LONG
 

  LOCAL pbstrKey AS DWORD

  strKey = UCODE$(strKey)

  pbstrKey = STRPTR(strKey)


  ! push ppvObj
  ! lea  eax, pbstrKey
  ! push eax
  ! mov  eax, riid
  ! push eax
  ! push pUnkReserved
  ! push pUnkOuter
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+28]
  ! mov  FUNCTION, eax

 

END FUNCTION

 

 

How to retrieve the license key

 

FUNCTION TB_GetRuntimeLicenseKey (BYVAL ProgramID AS STRING) AS STRING

   LOCAL hr AS LONG
   LOCAL ppICF AS DWORD
   LOCAL IID_IClassFactory2 AS GUID
   LOCAL ClassClsid AS GUID
   LOCAL tLicInfo AS LICINFO
   LOCAL strLicKey AS STRING

   ' Retrieve the CLSID associated with the PROGID of the component
   ClassClsid = CLSID$(ProgramID)

   ' Get a pointer to the IClassFactory2 interface
   IID_IClassFactory2 = GUID$("{b196b28f-bab4-101a-b69c-00aa00341d07}")
   hr = CoGetClassObject(ClassClsid, %CLSCTX_ALL, %NULL, IID_IClassFactory2, ppICF)
   IF hr THEN EXIT FUNCTION

   ' Fill the LICINFO structure
   tLicInfo.cbLicInfo = SIZEOF(tLicInfo)
   hr = IClassFactory2_GetLicInfo(ppICF, tLicInfo)

   ' If there is a runtime key available retrieve it
   IF tLicInfo.fRuntimeKeyAvail THEN
      hr = IClassFactory2_RequestLicKey(ppICF, 0, strLicKey)
      FUNCTION = strLicKey
   END IF

   ' Release the interface
   IUnknown_Release ppICF

END FUNCTION
 

 

Page last updated on Thursday, 16 March 2006 22:40:24 +0100