次の方法で共有


Class Factories and Licensing

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Class Factories and Licensing.

To create an instance of your OLE control, a container application calls a member function of the control's class factory. Because your control is an actual OLE object, the class factory is responsible for creating instances of your control. Every OLE control class must have a class factory.

Another important feature of OLE controls is their ability to enforce a license. ControlWizard allows you to incorporate licensing during the creation of your control project. For more information on control licensing, see the article ActiveX Controls: Licensing An ActiveX Control.

The following table lists several macros and functions used to declare and implement your control's class factory and to license of your control.

Class Factories and Licensing

DECLARE_OLECREATE_EX Declares the class factory for an OLE control or property page.
IMPLEMENT_OLECREATE_EX Implements the control's GetClassID function and declares an instance of the class factory.
BEGIN_OLEFACTORY Begins the declaration of any licensing functions.
END_OLEFACTORY Ends the declaration of any licensing functions.
AfxVerifyLicFile Verifies whether a control is licensed for use on a particular computer.

DECLARE_OLECREATE_EX

Declares a class factory and the GetClassID member function of your control class.

DECLARE_OLECREATE_EX
(class_name)   

Parameters

class_name
The name of the control class.

Remarks

Use this macro in the control class header file for a control that does not support licensing.

Note that this macro serves the same purpose as the following code sample:

   BEGIN_OLEFACTORY(CMyAxCtrl)
   END_OLEFACTORY(CMyAxCtrl)

IMPLEMENT_OLECREATE_EX

Implements your control's class factory and the GetClassID member function of your control class.

IMPLEMENT_OLECREATE_EX(
   class_name,   
    external_name,    
    l,   
    w1,   
    w2,   
    b1,   
    b2,   
    b3,   
    b4,   
    b5,   
    b6,   
    b7,
    b8)   

Parameters

class_name
The name of the control property page class.

external_name
The object name exposed to applications.

l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8
Components of the class's CLSID. For more information on these parameters, see the Remarks for [IMPLEMENT_OLECREATE]--brokenlink--(../Topic/not%20found.md#implement_olecreate.

Remarks

This macro must appear in the implementation file for any control class that uses the DECLARE_OLECREATE_EX macro or the BEGIN_OLEFACTORY and END_OLEFACTORY macros. The external name is the identifier of the OLE control that is exposed to other applications. Containers use this name to request an object of this control class.

BEGIN_OLEFACTORY

Begins the declaration of your class factory in the header file of your control class.

BEGIN_OLEFACTORY
(class_name)  

Parameters

class_name
Specifies the name of the control class whose class factory this is.

Remarks

Declarations of class factory licensing functions should begin immediately after BEGIN_OLEFACTORY.

END_OLEFACTORY

Ends the declaration of your control's class factory.

END_OLEFACTORY
(class_name)   

Parameters

class_name
The name of the control class whose class factory this is.

AfxVerifyLicFile

Call this function to verify that the license file named by pszLicFileName is valid for the OLE control.

BOOL AFXAPI AfxVerifyLicFile(
    HINSTANCE  hInstance,  
    LPCTSTR  pszLicFileName,  
    LPOLESTR  pszLicFileContents,  
    UINT cch = -1); 

Parameters

hInstance
The instance handle of the DLL associated with the licensed control.

pszLicFileName
Points to a null-terminated character string containing the license filename.

pszLicFileContents
Points to a byte sequence that must match the sequence found at the beginning of the license file.

cch
Number of characters in pszLicFileContents.

Return Value

Nonzero if the license file exists and begins with the character sequence in pszLicFileContents; otherwise 0.

Remarks

If cch is – 1, this function uses:

         _tcslen(pszLicFileContents);

See Also

Macros and Globals