Partager via


Creating Control Codes

If you are creating a resource type, you may need to create one or more control codes to expose specialized operations to other developers. By supporting these custom control codes in your resource DLL, you allow programmers to initiate the operations with ClusterResourceControl or ClusterResourceTypeControl.

For example, suppose you create a resource type for an application that generates a log file. You want other programmers to be able to read and change the location of the log file in their applications. To accomplish this, you could define control codes such as:

MYAPPNAME_GET_LOG_FILE_LOCATION

MYAPPNAME_SET_LOG_FILE_LOCATION

Programmers would use the control codes as ClusterResourceControl or ClusterResourceTypeControl parameters. The Cluster service would pass the control code to your resource DLL, which would handle the operation (the Resource Monitor, or course, would not know how to handle it).

To create a user-defined control code

  1. Review control code architecture.
  2. Use the CLUSCTL_USER_CODE macro to create the control code.
  3. Implement the control code in the ResourceControl and ResourceTypeControl entry points of your resource DLL.
  4. Document the procedures for using the control code, especially what the contents of the ClusterResourceControl and ClusterResourceTypeControl input and output buffers should be.

Example

The following code creates three control codes for a fictional resource type called "ServiceX".

#include <windows.h>
#include "ClusDocEx.h"

//////////////////////////////////////////////////////////////////////
//  DEFINE CONTROL CODES
//////////////////////////////////////////////////////////////////////

//  Object code

#define SERVICEX_OBJECT_CODE 221

//  Function codes

typedef enum SERVICEX_FUNCTION_CODES
 {
  SVCX_GET_LOGFILE_LOCATION = 22101,
  SVCX_SET_LOGFILE_LOCATION = 22102
 }
 SERVICEX_FUNCTION_CODES;


//  Create the control codes.

typedef enum SERVICEX_CONTROL_CODES
 {
  SERVICEX_GET_LOGFILE_LOCATION = CLUSCTL_USER_CODE( SVCX_GET_LOGFILE_LOCATION, SERVICEX_OBJECT_CODE ) | CLUS_ACCESS_READ,

  SERVICEX_SET_LOGFILE_LOCATION = CLUSCTL_USER_CODE( SVCX_SET_LOGFILE_LOCATION, SERVICEX_OBJECT_CODE ) | CLUS_ACCESS_ANY

 }
 SERVICEX_CONTROL_CODES; 


//--------------------------------------------------------------------
//  TODO:  Support these control codes in the ResourceControl and 
//         ResourceTypeControl entry points of the "ServiceX" 
//         resource DLL.  Document how the codes should be used.
//--------------------------------------------------------------------

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