共用方式為


Defining Structures and Constants

Some entry point functions require your resource DLL to describe and manage data in very specific ways. The following list describes the structures and constants that your DLL can or should define.

  1. Required. Define a function table for each resource type supported by your resource DLL. See CLRES_V1_FUNCTIONS.

  2. Required. Define global storage for the address of the LogEvent callback function. You need only one LogEvent callback per resource DLL.

  3. Required. Define global storage for the address of the SetResourceStatus callback function. You only need one SetResourceStatus callback per resource DLL.

  4. Required. Define a structure, class, or other object to manage instance data. The recommended way to do this is to define a resource structure. For more information see Implementing Instance Management.

  5. Required: Define the following objects if your resource type defines any private properties.

Any additional objects are optional. For example:

  • Semaphores, mutexes, and critical sections necessary to synchronize instance counts and other shared data.
  • Structures or classes that simplify the process of working with value lists and property lists.
  • Required dependency lists.
  • Constants, structures, classes, or other objects that specify the ideal configuration for the resource type. This would include property settings for the dependencies and dependents of the resource type and of the group in which they reside.

Example

The following example defines data in a resource DLL that supports two resource types, MyTypeAlpha and MyTypeBeta. For additional examples see Resource DLL Examples.

//////////////////////////////////////////////////////////////////////

//  Callback function pointers for the DLL.

    PSET_RESOURCE_STATUS_ROUTINE g_pfnSetResourceStatus = NULL;

    PLOG_EVENT_ROUTINE           g_pfnLogEvent          = NULL;

//////////////////////////////////////////////////////////////////////

//  Resource type name constants

    #define TYPE_NAME_ALPHA L"MyTypeAlpha"

    #define TYPE_NAME_BETA  L"MyTypeBeta"

//////////////////////////////////////////////////////////////////////

//  Function tables.

    
    CLRES_V1_FUNCTION_TABLE(
        g_FTable_Alpha,    
        CLRES_VERSION_V1_00,     
        MyTypeAlpha,                 
        NULL,                      
        NULL,                       
        MyTypeAlphaResourceControl,  
        MyTypeAlphaResourceTypeControl
    );
    
    CLRES_V1_FUNCTION_TABLE(
        g_FTable_Beta,
        CLRES_VERSION_V1_00,
        MyTypeBeta,
        NULL,              
        NULL,                     
        MyTypeBetaResourceControl,
        MyTypeBetaResourceTypeControl
    );
    
//////////////////////////////////////////////////////////////////////

//  Resource structures.

    typedef struct _INSTANCE_ALPHA
    {
        RESID             resid;
        PARAM_BLOCK_ALPHA propsActive;
        PARAM_BLOCK_ALPHA props;
        HCLUSTER          hCluster;
        HRESOURCE         hResource;
        SC_HANDLE         hService;
        DWORD             dwServicePid;
        HKEY              hkeyParameters;
        RESOURCE_HANDLE   hResourceHandle;
        LPWSTR            pszResourceName;
        CLUS_WORKER       cwWorkerThread;
        CLUSTER_RESOURCE_STATE state;
    } 
    INSTANCE_ALPHA, * PINSTANCE_ALPHA;
    
    typedef struct _INSTANCE_BETA
    {
        RESID                   resid;
        HCLUSTER                hCluster;
        HRESOURCE               hResource;
        HKEY                    hkeyParameters;
        RESOURCE_HANDLE         hResourceHandle;
        LPWSTR                  pszResourceName;
        CLUS_WORKER             cwWorkerThread;
        CLUSTER_RESOURCE_STATE  state;
    } 
    INSTANCE_BETA, * PINSTANCE_BETA;

//////////////////////////////////////////////////////////////////////

//  Private property data.
//  Only MyTypeAlpha defines private properties.
    
    #define PROP_NAME__MAXUSERS L"MaxUsers"
    #define PROP_MIN__MAXUSERS        (-1)
    #define PROP_MAX__MAXUSERS        (256)
    #define PROP_DEFAULT__MAXUSERS    (8)
    
    typedef struct _PARAM_BLOCK_ALPHA
    {
        LONG nMaxUsers;
    } 
    PARAM_BLOCK_ALPHA, * PPARAM_BLOCK_ALPHA;
    

    RESUTIL_PROPERTY_ITEM PROP_TABLE_ALPHA[] =
    {
        {    
            PROP_NAME__MAXUSERS, 
            NULL, 
            CLUSPROP_FORMAT_LONG, 
            (DWORD) PROP_DEFAULT__MAXUSERS, 
            (DWORD) PROP_MIN__MAXUSERS, 
            (DWORD) PROP_MAX__MAXUSERS, 
            RESUTIL_PROPITEM_REQUIRED, 
            FIELD_OFFSET( PARAM_BLOCK_ALPHA, 
                          nMaxUsers ) 
        },

        { 0 }
    };
    
//////////////////////////////////////////////////////////////////////

//  Define a semaphore to limit MyTypeAlpha instances to
//  one per cluster.  SIS = "single instance semaphore"

    #define SIS_ALPHA L"SISAlpha"
    static HANDLE g_hSIS = NULL;
    static PINSTANCE_ALPHA g_pInstance_Alpha = NULL;
    
//////////////////////////////////////////////////////////////////////